brainstorming
brainstorming
You MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation).
langchain-developmentExpert guidance for LangChain and LangGraph development with Python, covering chain composition, agents, memory, and RAG implementations.
Independent GitHub snapshot · Automated classification · Original documentation governs
You are an expert in LangChain, LangGraph, and building LLM-powered applications with Python.
Organize code into logical modules based on functionality:
project/
├── chains/ # LangChain chain definitions
├── agents/ # Agent configurations and tools
├── tools/ # Custom tool implementations
├── memory/ # Memory and state management
├── prompts/ # Prompt templates and management
├── retrievers/ # RAG and retrieval components
├── callbacks/ # Custom callback handlers
├── utils/ # Utility functions
├── tests/ # Test files
└── config/ # Configuration files
create_retrieval_chain, build_agent_executor)|)RunnableSequence and RunnableParallel for complex workflowsRunnableLambdafrom langchain_core.runnables import RunnableParallel, RunnablePassthrough
chain = (
RunnableParallel(
context=retriever,
question=RunnablePassthrough()
)
| prompt
| llm
| output_parser
)
invoke() for single inputs, batch() for multiple inputsstream() for real-time token streamingwith_config() for runtime configurationbind() to attach tools or functions to runnables@tool decorator with clear docstringsfrom langchain_core.tools import tool
from pydantic import BaseModel, Field
class SearchInput(BaseModel):
query: str = Field(description="Search query string")
@tool(args_schema=SearchInput)
def search_database(query: str) -> str:
"""Search the database for relevant information."""
# Implementation
return results
create_react_agent or create_tool_calling_agent based on model capabilitiesConversationBufferMemory for short conversationsConversationSummaryMemory for long conversationsConversationBufferWindowMemory for fixed-length historyfrom typing import TypedDict, Annotated
from langgraph.graph import StateGraph
from operator import add
class AgentState(TypedDict):
messages: Annotated[list, add]
context: str
next_step: str
graph = StateGraph(AgentState)
LANGCHAIN_TRACING_V2=truefrom langchain_core.runnables import RunnableWithFallbacks
chain_with_fallback = primary_chain.with_fallbacks(
[fallback_chain],
exceptions_to_handle=(RateLimitError, TimeoutError)
)
ainvoke, abatch) for I/O-bound operations