portia.execution_agents.one_shot_agent
A simple OneShotAgent optimized for simple tool calling tasks.
This agent invokes the OneShotToolCallingModel up to four times, but each individual attempt is a one-shot call. It is useful when the tool call is simple, minimizing cost. However, for more complex tool calls, the DefaultExecutionAgent is recommended as it will be more successful than the OneShotAgent.
ExecutionState Objects
class ExecutionState(MessagesState)
State for the execution agent.
OneShotToolCallingModel Objects
class OneShotToolCallingModel()
One-shot model for calling a given tool.
This model directly passes the tool and context to the language model (LLM) to generate a response. It is suitable for simple tasks where the arguments are already correctly formatted and complete. This model does not validate arguments (e.g., it will not catch missing arguments).
It is recommended to use the DefaultExecutionAgent for more complex tasks.
Arguments:
model
GenerativeModel - The language model to use for generating responses.tools
list[StructuredTool] - A list of tools that can be used during the task.agent
OneShotAgent - The agent responsible for managing the task.
Methods:
invoke(MessagesState)
- Invokes the LLM to generate a response based on the query, context, and past errors.
__init__
def __init__(model: GenerativeModel, tools: list[StructuredTool],
agent: OneShotAgent, tool_context: ToolRunContext) -> None
Initialize the OneShotToolCallingModel.
Arguments:
model
GenerativeModel - The language model to use for generating responses.tools
list[StructuredTool] - A list of tools that can be used during the task.agent
OneShotAgent - The agent that is managing the task.tool_context
ToolRunContext - The context for the tool.
invoke
def invoke(state: ExecutionState) -> dict[str, Any]
Invoke the model with the given message state.
This method formats the input for the language model using the query, context, and past errors, then generates a response by invoking the model.
Arguments:
state
ExecutionState - The state containing the messages and other necessary data.
Returns:
dict[str, Any]: A dictionary containing the model's generated response.
OneShotAgent Objects
class OneShotAgent(BaseExecutionAgent)
Agent responsible for achieving a task by using langgraph.
This agent performs the following steps:
- Extracts inputs from agent memory (if applicable)
- Calls the tool with unverified arguments.
- Retries tool calls up to 4 times.
Methods:
execute_sync()
- Executes the core logic of the agent's task, using the provided tool
__init__
def __init__(step: Step,
plan_run: PlanRun,
config: Config,
agent_memory: AgentMemory,
end_user: EndUser,
tool: Tool | None = None,
execution_hooks: ExecutionHooks | None = None) -> None
Initialize the OneShotAgent.
Arguments:
step
Step - The current step in the task plan.plan_run
PlanRun - The run that defines the task execution process.config
Config - The configuration settings for the agent.agent_memory
AgentMemory - The agent memory for persisting outputs.end_user
EndUser - The end user for the execution.tool
Tool | None - The tool to be used for the task (optional).execution_hooks
ExecutionHooks | None - The execution hooks for the agent.
execute_sync
def execute_sync() -> Output
Run the core execution logic of the task.
This method will invoke the tool with arguments
Returns:
Output
- The result of the agent's execution, containing the tool call result.