Skip to main content
All agents inherit from BaseAgent and implement a single method:
async def astream(self, input: str, *, ctx: Context) -> AsyncIterator[Event]:
    ...
Orchestrators and AgentTool call astream() on sub-agents, yielding AGENT_MESSAGE and TOOL_RESPONSE events throughout execution.

LlmAgent

The primary agent. Uses LangChain BaseChatModel with a manual tool-call loop.
from langchain_adk import LlmAgent

agent = LlmAgent(
    name="MyAgent",
    llm=llm,
    tools=[search_tool, calculator_tool],
    instructions="You are a research assistant.",   # or a Callable[[ReadonlyContext], str]
    description="Searches and calculates things.",
    planner=my_planner,         # optional BasePlanner
    output_schema=MySchema,     # optional: force structured output
    max_iterations=10,
    before_model_callback=None,
    after_model_callback=None,
    before_tool_callback=None,
    after_tool_callback=None,
)

Dynamic instructions

The instructions parameter accepts either a plain string or an instruction provider - a callable that receives a ReadonlyContext and returns a string:
def my_instructions(ctx: ReadonlyContext) -> str:
    user_name = ctx.state.get("user_name", "user")
    return f"You are helping {user_name}. Be concise."

agent = LlmAgent(name="Agent", llm=llm, instructions=my_instructions)

ReActAgent

A structured-reasoning variant that forces the LLM to emit explicit thought steps via with_structured_output() before acting. Extends LlmAgent - supports instructions, planner, callbacks, and all other LlmAgent features.
from langchain_adk import ReActAgent

agent = ReActAgent(
    name="ThinkingAgent",
    llm=llm,
    tools=[search_tool],
    instructions="You are a research assistant. Always cite your sources.",
    max_iterations=10,
)
Custom instructions are appended to the built-in ReAct system prompt under an “Additional instructions” section. Planners work the same way - their output is appended after the instructions. Yields events with types: AGENT_START -> AGENT_MESSAGE (thoughts/actions) -> TOOL_RESPONSE (observations) -> … -> AGENT_MESSAGE (final answer) -> AGENT_END.