Agent
CodeActAgentResponse
dataclass
CodeActAgentResponse(text: str, usage: CodeActModelUsage)
A response from an single interaction with a code action agent.
CodeActAgentTurn
CodeActAgentTurn(iter: AsyncIterator[CodeActModelTurn | CodeExecution | CodeActAgentResponse], trace_name: str, trace_input: dict[str, Any], trace_session_id: str | None = None)
A single interaction with the code action agent.
An interaction consists of a sequence of model interaction and code execution pairs, continuing until the code action model provides a final response or the maximum number of steps is reached.
Source code in freeact/agent.py
response
async
response() -> CodeActAgentResponse
Retrieves the final response from the code action agent for this interaction. Waits until the sequence of model interactions and code executions is complete.
Returns:
Type | Description |
---|---|
CodeActAgentResponse
|
The final response from the code action model as |
Raises:
Type | Description |
---|---|
MaxStepsReached
|
If the interaction exceeds the maximum number of steps without completion. |
Source code in freeact/agent.py
stream
async
stream() -> AsyncIterator[CodeActModelTurn | CodeExecution]
Streams the sequence of model interaction and code execution pairs as they occur:
CodeActModelTurn
: The current interaction with the code action modelCodeExecution
: The current execution of a code action in the code execution environment
The sequence continues until the model provides a final response. Once
the stream is consumed, response
is immediately available without waiting and contains the final response
text and accumulated usage statistics.
Raises:
Type | Description |
---|---|
MaxStepsReached
|
If the interaction exceeds the maximum number of steps without completion. |
Source code in freeact/agent.py
CodeActAgent
CodeActAgent(model: CodeActModel, executor: CodeExecutor)
An agent that iteratively generates and executes code actions to process user queries.
The agent implements a loop that:
- Generates code actions using a
CodeActModel
- Executes the code using a
CodeExecutor
- Provides execution feedback to the
CodeActModel
- Continues until the model generates a final response.
A single interaction with the agent is initiated with its run
method. The agent maintains conversational state and can have multiple interactions with the user.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
CodeActModel
|
Model instance for generating code actions |
required |
executor
|
CodeExecutor
|
Executor instance for executing code actions |
required |
Source code in freeact/agent.py
run
run(user_query: str, max_steps: int = 30, step_timeout: float = 120, **kwargs) -> CodeActAgentTurn
Initiates an interaction with the agent from a user query. The query
is processed through a sequence of model interaction and code execution
steps, driven by interacting with the returned CodeActAgentTurn
object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
user_query
|
str
|
The user query (a question, instruction, etc.) |
required |
max_steps
|
int
|
Maximum number of steps before raising |
30
|
step_timeout
|
float
|
Timeout in seconds per code execution step |
120
|
**kwargs
|
Additional keyword arguments passed to the model |
{}
|
Returns:
Name | Type | Description |
---|---|---|
CodeActAgentTurn |
CodeActAgentTurn
|
An object for retrieving the agent's processing steps and response. |
Raises:
Type | Description |
---|---|
MaxStepsReached
|
If the interaction exceeds |