agent.agent_loop
Agentic execution loop for tool-call-driven prompt execution.
The AgentLoop wraps an FFAIClientBase and executes multi-round tool-call loops: the LLM generates responses that may include tool calls, the loop executes those tools, feeds results back, and continues until the LLM produces a final answer without tool calls or the maximum round count is reached.
Agentic execution loop for tool-call-driven prompt execution.
The AgentLoop wraps an FFAIClientBase and executes multi-round tool-call loops: the LLM generates responses that may include tool calls, the loop executes those tools, feeds results back, and continues until the LLM produces a final answer without tool calls or the maximum round count is reached.
- class AgentLoop(client, tool_registry, max_rounds=5, tool_timeout=30.0, continue_on_tool_error=True)[source]
Bases:
objectExecutes agentic tool-call loops for a single prompt.
- Usage:
loop = AgentLoop(client, tool_registry, max_rounds=5) result = loop.execute(
prompt=”Search for information about X”, tools=[“search_tool”, “calculate”],
)
- Parameters:
client (FFAIClientBase)
tool_registry (ToolRegistry)
max_rounds (int)
tool_timeout (float)
continue_on_tool_error (bool)
- __init__(client, tool_registry, max_rounds=5, tool_timeout=30.0, continue_on_tool_error=True)[source]
Initialize the agent loop.
- Parameters:
client (FFAIClientBase) – AI client to use for LLM calls.
tool_registry (ToolRegistry) – Registry of tools available for execution.
max_rounds (int) – Maximum number of tool-call rounds.
tool_timeout (float) – Timeout in seconds for individual tool execution.
continue_on_tool_error (bool) – Whether to continue the loop if a tool fails.
- Return type:
None
- execute(prompt, tools, tool_choice='auto', **kwargs)[source]
Execute the agentic loop.
Calls the LLM with the prompt and available tools. If the response contains tool calls, executes them and feeds results back. Repeats until no tool calls or max_rounds is reached.
- Parameters:
- Returns:
AgentResult with response, tool call records, and round/LLM counts.
- Return type:
Classes
- class AgentLoop(client, tool_registry, max_rounds=5, tool_timeout=30.0, continue_on_tool_error=True)[source]
Bases:
objectExecutes agentic tool-call loops for a single prompt.
- Usage:
loop = AgentLoop(client, tool_registry, max_rounds=5) result = loop.execute(
prompt=”Search for information about X”, tools=[“search_tool”, “calculate”],
)
- Parameters:
client (FFAIClientBase)
tool_registry (ToolRegistry)
max_rounds (int)
tool_timeout (float)
continue_on_tool_error (bool)
- __init__(client, tool_registry, max_rounds=5, tool_timeout=30.0, continue_on_tool_error=True)[source]
Initialize the agent loop.
- Parameters:
client (FFAIClientBase) – AI client to use for LLM calls.
tool_registry (ToolRegistry) – Registry of tools available for execution.
max_rounds (int) – Maximum number of tool-call rounds.
tool_timeout (float) – Timeout in seconds for individual tool execution.
continue_on_tool_error (bool) – Whether to continue the loop if a tool fails.
- Return type:
None
- execute(prompt, tools, tool_choice='auto', **kwargs)[source]
Execute the agentic loop.
Calls the LLM with the prompt and available tools. If the response contains tool calls, executes them and feeds results back. Repeats until no tool calls or max_rounds is reached.
- Parameters:
- Returns:
AgentResult with response, tool call records, and round/LLM counts.
- Return type: