nat.agent.tool_calling_agent.agent#

Attributes#

Classes#

ToolCallAgentGraphState

State schema for the Tool Calling Agent Graph

ToolCallAgentGraph

Configurable LangGraph Tool Calling Agent. A Tool Calling Agent requires an LLM which supports tool calling.

Functions#

create_tool_calling_agent_prompt(→ str | None)

Create a Tool Calling Agent prompt from the config.

Module Contents#

logger#
class ToolCallAgentGraphState(/, **data: Any)#

Bases: pydantic.BaseModel

State schema for the Tool Calling Agent Graph

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

messages: list[langchain_core.messages.base.BaseMessage] = None#
class ToolCallAgentGraph(
llm: langchain_core.language_models.BaseChatModel,
tools: list[langchain_core.tools.BaseTool],
prompt: str | None = None,
callbacks: list[langchain_core.callbacks.base.AsyncCallbackHandler] = None,
detailed_logs: bool = False,
log_response_max_chars: int = 1000,
handle_tool_errors: bool = True,
return_direct: list[langchain_core.tools.BaseTool] | None = None,
)#

Bases: nat.agent.dual_node.DualNodeAgent

Configurable LangGraph Tool Calling Agent. A Tool Calling Agent requires an LLM which supports tool calling. A tool Calling Agent utilizes the tool input parameters to select the optimal tool. Supports handling tool errors. Argument “detailed_logs” toggles logging of inputs, outputs, and intermediate steps.

agent#
tool_caller#
return_direct = []#
async agent_node(state: ToolCallAgentGraphState)#
async conditional_edge(state: ToolCallAgentGraphState)#
async tool_node(state: ToolCallAgentGraphState)#
async tool_conditional_edge(
state: ToolCallAgentGraphState,
) nat.agent.base.AgentDecision#

Determines whether to continue to the agent or end graph execution after a tool call.

Args:

state: The current state of the Tool Calling Agent graph containing messages and tool responses.

Returns:

AgentDecision: TOOL to continue to agent for processing, or END to terminate graph execution. Returns END if the tool is in return_direct list, otherwise returns TOOL to continue processing.

async _build_graph(
state_schema: type,
) langgraph.graph.state.CompiledStateGraph#
async build_graph() langgraph.graph.state.CompiledStateGraph#
create_tool_calling_agent_prompt(
config: nat.agent.tool_calling_agent.register.ToolCallAgentWorkflowConfig,
) str | None#

Create a Tool Calling Agent prompt from the config.

Args:

config (ToolCallAgentWorkflowConfig): The config to use for the prompt.

Returns:

ChatPromptTemplate: The Tool Calling Agent prompt.