𝗕𝘂𝗶𝗹𝗱𝗶𝗻𝗴 𝗔𝗜 𝗔𝗴𝗲𝗻𝘁𝘀 𝘄𝗶𝘁𝗵 𝗟𝗮𝗻𝗴𝗖𝗵𝗮𝗶𝗻
LangChain agents use LangGraph to work. The model calls tools in a loop. It continues until it finds a final answer.
You can build a support triage agent using createAgent. You need three things:
- A model
- A list of tools
- A system prompt
How the loop works: The model takes a turn. In one turn, it does one of two things:
- It returns text to end the run.
- It calls a tool. LangChain runs the tool and starts a new turn with the result.
You should set a recursionLimit. This prevents the agent from looping forever.
How to define tools: Use the tool function with a Zod schema. Give each tool a name and a description. This helps the model decide when to use it.
Example flow for a support agent:
- User asks a question.
- Model calls get_customer.
- Model calls get_invoice.
- Model calls search_knowledge_base.
- Model creates a ticket or gives an answer.
Comparing SDKs:
LangChain:
- Best for RAG and complex agent stacks.
- Uses tool() with Zod schemas.
- Uses agent.invoke or agent.stream.
- Uses LangGraph for memory.
Vercel AI SDK:
- Best for TypeScript apps.
- Uses tool() with inputSchema.
- Uses generateText.
OpenAI Agents SDK:
- Best for OpenAI-first workflows.
- Uses tool() with Zod parameters.
- Uses run().
Choose LangChain if you need document loaders and retrievers in one place. Choose Vercel or OpenAI if you want a simple agent layer.
Source: https://dev.to/zsevic/building-ai-agents-with-langchain-5e69
Optional learning community: https://t.me/GyaanSetuAi