掌握flow的状态(statement)管理

掌握流程的状态管理 理解流程中状态的作用: 状态系统允许你维护上下文,在步骤之间共享数据,并构建复杂的应用逻辑 为什么状态管理很重要: 1.维持上下文 2.构建复杂的条件逻辑 3.创建持久化应用 4.优雅地处理错误 5.拓展你的应用 6.实现对话式的应用 ...

FrameworksCrewAI
3 分钟1091 字chenghaoning51

DeepFlow

1.langgraph.json文件的作用 when: 使用Langgraph cli部署本地API服务 部署到langgraph cloud/langsmith deployment 使用langgraph studio及逆行调试 不需要: 使用传统的后端API服务;纯脚本/嵌入式开发 ...

FrameworksLangChain
2 分钟519 字chenghaoning51

Human-in-the-loop

By checking each tool call against a configurable policy 如果需要暂停,middleware将会issue an interrupt来暂停执行 图状态将会使用LangGraph的persistence layer来保存,因此可以pause and resume later ...

FrameworksLangChain
3 分钟1412 字chenghaoning51

Message

Message Carrying both the content and metadata which represent the state Messages contain: Role: identifies the message type(system,user) Content: the actual content Metadata: optional fields: such as information,message IDs,and token usage This is the standard message type Basic usage The easiest way to use message is to create message objects and pass them to a model when invoking Text prompts String Ideal for generation tasks where you don’t need to retain. ...

FrameworksLangChain
2 分钟886 字chenghaoning51

Overview

The situation that fits middleware Tracking agent behavior with logging, analytics, and debugging. Transforming prompts, tool selection, and output formatting. Adding retries, fallbacks, and early termination logic. Applying rate limits, guardrails, and PII detection. The agent loop the core agent loop involves calling a model ,letting it choose tools to execute,and then finishing when it calls no more tools Middleware在其中的作用: exposes hooks before and after each of these steps ...

FrameworksLangChain
1 分钟246 字chenghaoning51

构建第一个 CrewAI 项目

第一步:创建新的CrewAI项目 1 crewai create crew research_crew 第二步:探索项目结构 遵循py项目的最佳实践,通过分离配置文件和实现代码,在不修改源代码的情况下修改团队的行为 第三步:配置你的智能体 通过修改agent.yaml来定义智能体 role;goal;backstory;llm ...

FrameworksCrewAI
1 分钟287 字chenghaoning51

Long-term-memory

Across sessions and conversations Long-term memory 建立在Lang Graph stores,存储的形式:JSON documents organized by namespace and key Usage 为了给一个agent添加memory功能,在使用create_agent时create a store and pass it to agent ...

FrameworksLangChain
2 分钟846 字chenghaoning51

Models

In addition to text generation,many LLMs provide :tool calling,Structured output,Multimodality,Reasoning different model excel at different tasks LangChain has Standard model interface,which allow you to experiment with and switch models Basic usage 1.with agents 2.Standalone(outside the agent loop) Initialize a model the easiest way: use init_chat_model 1 2 3 4 5 6 import os from langchain.chat_models import init_chat_model os.environ["OPENAI_API_KEY"] = "sk-..." model = init_chat_model("gpt-5.5") key method: invoke,streaming.patch(批量处理) ...

FrameworksLangChain
4 分钟1543 字chenghaoning51

Open-SWE

Convention part 1.使用async方法,只在必须的时候才使用sync方法(不是通用的设计范式): 约束之一为:Use async-only implementations. Add a sync method only when an interface requires it, and then raise NotImplementedError. 1.使用async方法优化并发性能 2.使用NotImplementedError显式告知为提供async实现,采用同步方法 ...

FrameworksLangChain
5 分钟2482 字chenghaoning51

Prebuilt Middleware

Tool error 捕获工具异常,并且转化为ToolMessage,模型收到信息并且从中修复 API reference: ToolErrorMiddleware 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 from langchain.agents import create_agent from langchain.agents.middleware import ToolErrorMiddleware, ToolRetryMiddleware def on_error(exc: Exception, request: ToolCallRequest) -> str | None: # Surface ValueError to the model so it can correct the input if isinstance(exc, ValueError): return f"`{request.tool_call['name']}` failed: {type(exc).__name__}. Fix the input and retry." # Let all other exceptions propagate (halts the run) return None # Async-only usage async def aon_error(exc: Exception, request: ToolCallRequest) -> str | None: if isinstance(exc, ConnectionError): return f"Tool `{request.tool_call['name']}` encountered a connection error." return None agent = create_agent( model="gpt-5.5", tools=[search_tool, database_tool], middleware=[ # Place retry inner so exceptions reach ToolErrorMiddleware after retries are exhausted ToolRetryMiddleware(max_retries=3, on_failure="error"), ToolErrorMiddleware(on_error=on_error, tools=["search_tool"]), ], ) # Async-only: pass aon_error alone (do not pass on_error) async_agent = create_agent( model="gpt-5.5", tools=[api_tool], middleware=[ToolErrorMiddleware(aon_error=aon_error)], ) Tool retry 通过可配置的指数避退机制来自动重试失败tool calls ...

FrameworksLangChain
3 分钟1373 字chenghaoning51