Model
This module defines the interfaces of code action models. A code action model is a model that responds with code if it decides to perform an action in the environment.
This module defines the core interfaces that code action models must implement
to work with the freeact
agent system. It defines abstract base classes for:
- The main model interface (
CodeActModel
) - Model interaction turns (
CodeActModelTurn
) - Model responses (
CodeActModelResponse
)
CodeActModel
Bases: ABC
Interface for models that can generate code actions.
A code action model handles both initial user queries and feedback from code execution results. It decides when to generate code for execution and when to provide final responses to the user.
feedback
abstractmethod
feedback(feedback: str, is_error: bool, tool_use_id: str | None, tool_use_name: str | None, **kwargs) -> CodeActModelTurn
Create a new interaction turn from execution feedback.
Initiates a new interaction based on feedback from previous code execution, allowing the model to refine or correct its responses. A feedback turn must follow a previous request turn or feedback turn.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
feedback
|
str
|
The feedback text from code execution. |
required |
is_error
|
bool
|
Whether the feedback represents an error condition. |
required |
tool_use_id
|
str | None
|
Identifier for the specific tool use instance. |
required |
tool_use_name
|
str | None
|
Name of the tool that was used. |
required |
**kwargs
|
Additional model-specific parameters for the feedback. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
CodeActModelTurn |
CodeActModelTurn
|
A new turn object representing this interaction. |
Source code in freeact/model/base.py
request
abstractmethod
request(user_query: str, **kwargs) -> CodeActModelTurn
Creates a new interaction turn from a user query.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
user_query
|
str
|
The user's input query or request |
required |
**kwargs
|
Additional model-specific parameters |
{}
|
Returns:
Name | Type | Description |
---|---|---|
CodeActModelTurn |
CodeActModelTurn
|
A new turn object representing this interaction. |
Source code in freeact/model/base.py
CodeActModelResponse
dataclass
Bases: ABC
A response from a code action model.
Represents a single response from the model, which may contain executable code, error information, and tool usage metadata.
Attributes:
Name | Type | Description |
---|---|---|
text |
str
|
The raw text response from the model. |
is_error |
bool
|
Whether this response represents an error condition. |
token_usage |
Dict[str, int]
|
Provider-specific token usage data. |
CodeActModelTurn
Bases: ABC
A single turn of interaction with a code action model.
Supports both bulk response retrieval and incremental streaming of the model's output. Each turn represents one complete model interaction, whether from a user query or execution feedback.
response
abstractmethod
async
response() -> CodeActModelResponse
Get the complete response for this model interaction turn.
Waits for and returns the full model response, including any code blocks and metadata about tool usage.
stream
abstractmethod
stream(emit_retry: bool = False) -> AsyncIterator[str | StreamRetry]
Stream the model's response as it is generated.
Yields chunks of the response as they become available, allowing for real-time processing of model output.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
emit_retry
|
bool
|
If |
False
|
Yields:
Type | Description |
---|---|
AsyncIterator[str | StreamRetry]
|
str | StreamRetry: Either a chunk of the response text, or a |