This repository was archived by the owner on Feb 6, 2026. It is now read-only.
generated from JoshuaC215/agent-service-toolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
Creating Agents
Janardhan B edited this page May 5, 2025
·
1 revision
This guide explains how to create and register new LangGraph agents in the Deployment Kit.
Agents are defined in the src/agents directory and registered in src/agents/agents.py.
- Create a new Python file in
src/agents(e.g.,my_agent.py) - Define your agent using LangGraph:
from typing import Annotated, TypedDict
from langgraph.graph import StateGraph, START, END
from langgraph.graph.message import add_messages
from langchain.chat_models import init_chat_model
# Define your agent's state
class State(TypedDict):
messages: Annotated[list, add_messages]
# Add any additional state fields
# Create the graph
graph_builder = StateGraph(State)
# Initialize your LLM
llm = init_chat_model("openai:gpt-4-turbo") # Or your preferred model
# Define nodes
async def process(state: State):
return {"messages": [await llm.ainvoke(state["messages"])]}
# Add nodes
graph_builder.add_node("process", process)
# Add edges
graph_builder.add_edge(START, "process")
graph_builder.add_edge("process", END)
# Compile the graph
my_agent = graph_builder.compile()Open src/agents/agents.py and register your agent:
from agents.my_agent import my_agent
# Update the agents dictionary
agents = {
# Existing agents
"research-assistant": Agent(
description="A research assistant with web search and calculator.",
graph=research_assistant
),
# Your new agent
"my-agent": Agent(
description="Description of your agent",
graph=my_agent
)
}To make your agent the default, update the DEFAULT_AGENT variable in src/agents/agents.py:
DEFAULT_AGENT = "my-agent"You can test your agent directly:
python src/run_agent.pyOr start the service and test via API:
python src/run_service.py© 2024 LangGraph Deployment Kit by Janardhan B | MIT License | Last updated: May 6, 2025