LangChain – Agents
Table Of Contents:
- What Is An Agent?
- Core Components
- Model Component
- Tools Component
- System Prompt
- Structured Output
- Invocation
- Streaming
- Configure The Harness
(1) What Is An Agent ?
from langchain.agents import create_agent
agent = create_agent(
model = "ollama:qwen3:0.6b",
tools= tools,
system_prompt="Your System Prompt"
) (2) Core Components Of Agent
(3) Model Component
from langchain.agents import create_agent
agent = create_agent(
model="qwen3:0.6b",
tools=[tools],
system_prompt = "System Prompt"
) (4) Tools Component
from langchain.agents import create_agent
from langchain.tools import tools
@tool
def search(query:str)->str:
"""Search For Information"""
return f"Result For {query}"
agent = create_agent(
model="ollama:qwen3:0.6b",
tools = [search],
system_prompt = "You Are An Healpful AI Assistant"
)
(5) System Prompt
agent = create_agent(
model = "ollama:qwen3:0.6b",
tools = [tools],
system_prompt = "You Will Answar My Questions"
) (6) Structured Output
from pydentic import BaseModel
from langchain.agents import create_agents
class Answer(BaseModel):
summary:str
confidence:float
agent = create_agent(
model = "ollama:qwen3:0.6b",
tools = [tools],
system_prompt = "System Prompt",
response_format = Answer
)
(7) Agent Invocation
from langchain.agents create_agent
from langchain_core.utils.uuid import uuid7
from langgraph.checkpoint.memory import InMemorySaver
agent = create_agent(
model="ollama:qwen3:0.6m",
tools=[],
checkpointer = InMemorySaver(),
)
config = {"configurable": {"thread_id": str(uuid7())}}
result = agent.invoke({
"messages": [{"role": "user", "content":"What Is The Weather In Bhubaneswar"}],
config = config,
})
# A Next Conversation Uses The Same Thread_Id
result = agent.invoke({"messages":[{"role":"user", "content":"What About Tomorrow"}]},
config = config
) (8) How To Add Agent State ?
I Want To Start A New Conversation:
(9) How To Add Agent Context ?
(10) Streaming
