Custom RAG Agent with LangChain
note
This article is for custom agent development: writing a Python agent class because the built-in configurable agent is not enough. For standard search and retrieval-augmented generation, configure the built-in agent with the CLI instead - see Configuring Tools.
Use this pattern when you want to run a LangChain retrieval pipeline inside an Agents SDK agent. The example below uses ZAVLangchainStore as the retriever source and ChatOpenAI as the LangChain chat model.
Prerequisites
- Completed Getting Started with the Agents SDK
- Familiar with Custom Agent Development
Install the LangChain extra:
pip install zetaalpha.agents[langchain,langchain-openai]
Step 1: Create a Custom Agent
Change to your agents project directory and scaffold a custom agent:
za agents add --custom "my_langchain_rag_agent"
This creates my_langchain_rag_agent.py in your agents project:
<agents project>/
├── .gitignore
├── __init__.py
├── my_langchain_rag_agent.py
├── agent_setups.json
├── llm_configurations.json