一个简单的示例
| |
Build a real-world agent:
- Detailed System Prompt
- Create Tools
- Model Configuration
- Conversational memory
- Deep agents
- Testing
1.Define the system prompt
defines your agent’s role and behavior. Keep it specific and actionable.
2.Craete tools
Tools let a model interact with external systems by calling functions you define. Tools can depend on runtime context and also interact with agent memory.
Tools should be well-documented: their name,description,parameters will become part of the model’s prompt. LangChain’s tool decorator adds metadata and enables runtime injection with the ToolRunTime paramete.
3.Configure your model
Set up your language model with the right parameters foe your use case
4.Add memory
Add memory to your agent to maintain state across interactions. This allows the agent to remember previous conversations and context.
5.Create and run the agent
Tow different Frameworks for creating agents: LangChain agents and deep agents Use deep agents when you want maximum with minimal setup; Choose LangChain agents when you need fine-grained contorl.
6.Review the results
相较于LangChain, deep agent拥有更多定义好的功能:
- 使用内置的
write_todos工具规划其方法,以分解研究任务。 - 通过调用
fetch_text_from_url工具加载文件以收集信息。 - 通过使用文件系统工具(
grep和read_file)来管理上下文。 - 生成子智能体:根据需要将复杂的子任务委派给专门的子智能体。
For LangChain agents, you must implement more capabilities to get a similar lever of service and can customize them along the way as needed
In short,deep agent is well-organized and provides many integrated tools and LangChain can fit custom needs better, but requires implementing more functionalities.
Trace agent calls
Use LangSmith to trace LLM calls and inspect what is going on inside your agent.
Emmm, you should sign up for a LangSmith account first. Besides,you can also set up LangSmith Engine which monitors your traces,detects issues ,and preposes fixes.