Skip to content

Langgraph react agent

LangGraph ReAct Agent implementation.

A ReAct agent template built on LangGraph that can use either lm_invoker or LangChain BaseChatModel.

Authors

Christian Trisno Sen Long Chen (christian.t.s.l.chen@gdplabs.id) Fachriza Adhiatma (fachriza.d.adhiatma@gdplabs.id) Raymond Christopher (raymond.christopher@gdplabs.id)

LangChainAgent(name, instruction=DEFAULT_INSTRUCTION, model=None, tools=None, agents=None, description=None, thread_id_key='thread_id', event_emitter=None, tool_output_manager=None, **kwargs)

Bases: LangGraphReactAgent

Alias for LangGraphReactAgent.

Initialize the LangGraph ReAct Agent.

Parameters:

Name Type Description Default
name str

The name of the agent.

required
instruction str

The system instruction for the agent.

DEFAULT_INSTRUCTION
model BaseChatModel | str | Any | None

The model to use (lm_invoker, LangChain model, string, etc.).

None
tools Sequence[BaseTool] | None

Sequence of LangChain tools available to the agent.

None
agents Sequence[Any] | None

Optional sequence of sub-agents for delegation (coordinator mode).

None
description str | None

Human-readable description of the agent.

None
thread_id_key str

Key for thread ID in configuration.

'thread_id'
event_emitter EventEmitter | None

Optional event emitter for streaming updates.

None
tool_output_manager ToolOutputManager | None

Optional ToolOutputManager instance for tool output management. When provided, enables tool output storage, reference resolution, and sharing capabilities. This enables multi-agent workflows where agents can access each other's tool outputs. If None, tool output management is disabled for this agent.

None
**kwargs Any

Additional keyword arguments passed to BaseLangGraphAgent.

{}

LangGraphAgent(name, instruction=DEFAULT_INSTRUCTION, model=None, tools=None, agents=None, description=None, thread_id_key='thread_id', event_emitter=None, tool_output_manager=None, **kwargs)

Bases: LangGraphReactAgent

Alias for LangGraphReactAgent.

Initialize the LangGraph ReAct Agent.

Parameters:

Name Type Description Default
name str

The name of the agent.

required
instruction str

The system instruction for the agent.

DEFAULT_INSTRUCTION
model BaseChatModel | str | Any | None

The model to use (lm_invoker, LangChain model, string, etc.).

None
tools Sequence[BaseTool] | None

Sequence of LangChain tools available to the agent.

None
agents Sequence[Any] | None

Optional sequence of sub-agents for delegation (coordinator mode).

None
description str | None

Human-readable description of the agent.

None
thread_id_key str

Key for thread ID in configuration.

'thread_id'
event_emitter EventEmitter | None

Optional event emitter for streaming updates.

None
tool_output_manager ToolOutputManager | None

Optional ToolOutputManager instance for tool output management. When provided, enables tool output storage, reference resolution, and sharing capabilities. This enables multi-agent workflows where agents can access each other's tool outputs. If None, tool output management is disabled for this agent.

None
**kwargs Any

Additional keyword arguments passed to BaseLangGraphAgent.

{}

LangGraphReactAgent(name, instruction=DEFAULT_INSTRUCTION, model=None, tools=None, agents=None, description=None, thread_id_key='thread_id', event_emitter=None, tool_output_manager=None, **kwargs)

Bases: LangGraphHitLMixin, BaseLangGraphAgent

A ReAct agent template built on LangGraph.

This agent can use either: - An LMInvoker (if self.lm_invoker is set by BaseAgent) - A LangChain BaseChatModel (if self.model is set by BaseAgent)

The graph structure follows the standard ReAct pattern: agent -> tools -> agent (loop) -> END

Initialize the LangGraph ReAct Agent.

Parameters:

Name Type Description Default
name str

The name of the agent.

required
instruction str

The system instruction for the agent.

DEFAULT_INSTRUCTION
model BaseChatModel | str | Any | None

The model to use (lm_invoker, LangChain model, string, etc.).

None
tools Sequence[BaseTool] | None

Sequence of LangChain tools available to the agent.

None
agents Sequence[Any] | None

Optional sequence of sub-agents for delegation (coordinator mode).

None
description str | None

Human-readable description of the agent.

None
thread_id_key str

Key for thread ID in configuration.

'thread_id'
event_emitter EventEmitter | None

Optional event emitter for streaming updates.

None
tool_output_manager ToolOutputManager | None

Optional ToolOutputManager instance for tool output management. When provided, enables tool output storage, reference resolution, and sharing capabilities. This enables multi-agent workflows where agents can access each other's tool outputs. If None, tool output management is disabled for this agent.

None
**kwargs Any

Additional keyword arguments passed to BaseLangGraphAgent.

{}

define_graph(graph_builder)

Define the ReAct agent graph structure.

Parameters:

Name Type Description Default
graph_builder StateGraph

The StateGraph builder to define the graph structure.

required

Returns:

Type Description
CompiledStateGraph

Compiled LangGraph ready for execution.

ReactAgentState

Bases: TypedDict

State schema for the ReAct agent.

Includes messages, step tracking, optional event emission support, artifacts, references, metadata, and tool output management for efficient tool result sharing and reference resolution.

ToolCallContext(config, state, pending_artifacts, hitl_decision=None) dataclass

Context information for executing a single tool call.