Loading...
Loading...
Compare original and translation side by side
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 filesproject/
├── chains/ # LangChain 链定义
├── agents/ # Agent 配置与工具
├── tools/ # 自定义工具实现
├── memory/ # 内存与状态管理
├── prompts/ # 提示词模板与管理
├── retrievers/ # RAG 与检索组件
├── callbacks/ # 自定义回调处理器
├── utils/ # 工具函数
├── tests/ # 测试文件
└── config/ # 配置文件create_retrieval_chainbuild_agent_executorcreate_retrieval_chainbuild_agent_executor|RunnableSequenceRunnableParallelRunnableLambdafrom langchain_core.runnables import RunnableParallel, RunnablePassthrough
chain = (
RunnableParallel(
context=retriever,
question=RunnablePassthrough()
)
| prompt
| llm
| output_parser
)|RunnableSequenceRunnableParallelRunnableLambdafrom langchain_core.runnables import RunnableParallel, RunnablePassthrough
chain = (
RunnableParallel(
context=retriever,
question=RunnablePassthrough()
)
| prompt
| llm
| output_parser
)invoke()batch()stream()with_config()bind()invoke()batch()stream()with_config()bind()@toolfrom 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@toolfrom 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 resultscreate_react_agentcreate_tool_calling_agentcreate_react_agentcreate_tool_calling_agentConversationBufferMemoryConversationSummaryMemoryConversationBufferWindowMemoryConversationBufferMemoryConversationSummaryMemoryConversationBufferWindowMemoryfrom 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)from 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=trueLANGCHAIN_TRACING_V2=truefrom langchain_core.runnables import RunnableWithFallbacks
chain_with_fallback = primary_chain.with_fallbacks(
[fallback_chain],
exceptions_to_handle=(RateLimitError, TimeoutError)
)from langchain_core.runnables import RunnableWithFallbacks
chain_with_fallback = primary_chain.with_fallbacks(
[fallback_chain],
exceptions_to_handle=(RateLimitError, TimeoutError)
)ainvokeabatchainvokeabatch