AI Interfaces
For end-users
This section is addressed to end-users who want to use the AI interfaces.
If you are a developer who wants to extend the AI interfaces, please refer to the Base AI interface section.
The AI interfaces are the classes that handle a conversation between the
Agent and the LLM. Here, conversation can mean
a single turn, or multiple turns. This abstracted away by the run
and arun methods:
you just need to pass a list of messages, and the AI interface will take care
of the rest.
Ultimately, the AI interface will return an AIInterfacePayload
object, which contains
the response from the LLM, the cost, and the finish reason. Through its
result
attribute, it can also contain a specific structured output schema.
Why is this useful?¶
When we need to create an Agent that executes
a Task in multiple steps, we need to use two
different prompts. For instance, you might want to start by planning the steps
of the task, and then execute them one by one. This requires two different
prompts; this is where the AI interfaces come in handy.
In this section, we will see the pre-loaded AI interfaces that come with Conatus:
PlainAIInterface, which is a simple AI interface that can be used for very simple interactions.ReactAIInterface, which is a ReAct-style AI interface that can be used to execute aTask.PlanningAIInterface, which connects to aRuntimeobject, and is used to plan the steps of aTask.ExecutionAIInterface, which also connects to aRuntimeobject, and is used to execute the steps of aTask.ComputerUseAIInterface, which is used to leverage the computer-use abilities of LLMs.
If you need to create your own AI interface, you can extend the
BaseAIInterface
class. For more information, see the Base AI interface API
section, or the
How-to on custom AI interfaces
section.
conatus.agents.ai_interfaces.plain.PlainAIInterface
¶
PlainAIInterface(
*,
user_prompt: str,
system_prompt: str | None = None,
output_schema: type[Result] | None = None,
task_config: ConsolidatedTaskConfig | None = None,
run_writer: FileWriter | None = None,
model_config: ModelConfig | ModelConfigTD | None = None,
model_type: ModelType | None = None,
interface_name: str | None = None,
max_turns: int | None = None,
actions: (
Collection[Action]
| Sequence[RawAction]
| ActionStarterPack
| None
) = None,
stop_if_no_tool_calls: bool = True,
**kwargs: ParamType
)
Bases: BaseAIInterface[Result]
An AI interface designed for very simple interactions.
The main distinction of this AI interface is that all it takes is a
user_prompt and optionally a system_prompt. You can also pass an
output_schema, which will be used to validate the output of the AI
interface.
from dataclasses import dataclass
from conatus.agents.ai_interfaces.plain import PlainAIInterface
@dataclass
class Macros:
calories: int
protein: float
carbs: float
fat: float
food_items = ["slice of pizza", "pot of yogurt", "ounce of cheese"]
for item in food_items:
ai_interface = PlainAIInterface(
user_prompt=f"What are (roughly) the macros for {item}?",
output_schema=Macros,
model_type="reasoning",
)
payload = ai_interface.run()
print(f"{item}: {payload.result}")
# > slice of pizza: Macros(calories=285, protein=12.0, carbs=36.0, fat=10.0)
# > pot of yogurt: Macros(calories=100, protein=6.0, carbs=12.0, fat=2.0)
# > ounce of cheese: Macros(calories=110, protein=7.0, carbs=1.0, fat=9.0)
| PARAMETER | DESCRIPTION |
|---|---|
user_prompt
|
The user prompt for the AI interface.
TYPE:
|
system_prompt
|
The system prompt for the AI interface.
TYPE:
|
output_schema
|
The output schema for the AI interface.
TYPE:
|
task_config
|
The task configuration for the AI interface.
TYPE:
|
run_writer
|
The writer used to log run information.
TYPE:
|
model_config
|
The configuration for the model.
TYPE:
|
model_type
|
The type of model to use for the AI interface. If
TYPE:
|
interface_name
|
The name of the AI interface. Will otherwise be the snake case of the class name.
TYPE:
|
actions
|
The actions to use for the AI interface.
TYPE:
|
max_turns
|
The maximum number of turns the AI interface can take. Defaults to 1, but can be overridden by the subclass or the user in the constructor.
TYPE:
|
stop_if_no_tool_calls
|
Whether to stop the run if no tool calls are
made. Defaults to
TYPE:
|
kwargs
|
Additional parameters for the AI interface.
TYPE:
|
Source code in conatus/agents/ai_interfaces/plain.py
arun
async
¶
arun(
conversation_history: Collection[
ConversationAIMessage
] = (),
conversation_history_id: str | None = None,
conversation_history_system_message: (
SystemAIMessage | None
) = None,
) -> AIInterfacePayload[Result]
Run the AI interface asynchronously.
For more information, see BaseAIInterface.run
.
| PARAMETER | DESCRIPTION |
|---|---|
conversation_history
|
The conversation history, as a list of
TYPE:
|
conversation_history_id
|
The ID of the conversation history. This should be used when dealing with stateful AI interfaces.
TYPE:
|
conversation_history_system_message
|
The system message of the conversation history.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AIInterfacePayload[Result]
|
The response from the AI interface. |
Source code in conatus/agents/ai_interfaces/base.py
run
¶
run(
*,
conversation_history: Collection[
ConversationAIMessage
] = (),
conversation_history_id: str | None = None,
conversation_history_system_message: (
SystemAIMessage | None
) = None
) -> AIInterfacePayload[Result]
Run the AI interface.
This method abstracts away the logic of interacting with the
AI models, and returns a
AIInterfacePayload
from which the Agent can extract
the result, the cost of the interactions, etc.
If the user wishes to include a previous conversation, they can
provide a list of ConversationAIMessage
objects, and / or a string that will identify the conversation.
| PARAMETER | DESCRIPTION |
|---|---|
conversation_history
|
The conversation history, as a list of
TYPE:
|
conversation_history_id
|
The ID of the conversation history. This should be used when dealing with stateful AI interfaces.
TYPE:
|
conversation_history_system_message
|
The system message of the conversation history.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AIInterfacePayload[Result]
|
The payload of the run. |
Source code in conatus/agents/ai_interfaces/base.py
conatus.agents.ai_interfaces.react.ReactAIInterface
¶
ReactAIInterface(
*,
runtime: Runtime,
task_definition: TaskDefinition,
task_config: ConsolidatedTaskConfig,
run_writer: FileWriter | None = None,
model_config: ModelConfig | ModelConfigTD | None = None,
model_type: ModelType | None = None,
computer_use_mode: bool = False,
only_keep_one_computer_use_environment: bool = True,
interface_name: str | None = None,
max_turns: int | None = None,
instructions: str | None = None,
stop_if_no_tool_calls: bool = False,
**kwargs: ParamType
)
Bases: ExecutionAIInterface
Simple, ReAct-style AI interface.
It requires a Runtime object, a
TaskDefinition and a
TaskConfig object to be passed to the
constructor.
One notable aspect of this AI interface is that it forces the
Runtime object to hide variables from the AI.
This means that (1) only actions with JSON-serializable arguments are
supported, and (2) the AI will not be able to see the variables that are
not part of the task.
| PARAMETER | DESCRIPTION |
|---|---|
runtime
|
The runtime state of the agent.
TYPE:
|
task_definition
|
The task definition of the agent.
TYPE:
|
task_config
|
The task configuration of the agent.
TYPE:
|
run_writer
|
The writer used to log run information.
TYPE:
|
model_config
|
The configuration for the model.
TYPE:
|
model_type
|
The type of model to use for the AI interface. If
TYPE:
|
computer_use_mode
|
Whether to use computer use mode.
TYPE:
|
only_keep_one_computer_use_environment
|
Whether to only keep one computer use environment.
TYPE:
|
interface_name
|
The name of the AI interface. Will otherwise be the snake case of the class name.
TYPE:
|
max_turns
|
The maximum number of turns the AI interface can take. Defaults to 1, but can be overridden by the subclass or the user in the constructor.
TYPE:
|
instructions
|
The instructions for the AI interface.
TYPE:
|
stop_if_no_tool_calls
|
Whether to stop the run if no tool calls are
made. Defaults to
TYPE:
|
kwargs
|
Additional parameters for the AI interface.
TYPE:
|
Source code in conatus/agents/ai_interfaces/react.py
arun
async
¶
arun(
conversation_history: Collection[
ConversationAIMessage
] = (),
conversation_history_id: str | None = None,
conversation_history_system_message: (
SystemAIMessage | None
) = None,
) -> AIInterfacePayload[Result]
Run the AI interface asynchronously.
For more information, see BaseAIInterface.run
.
| PARAMETER | DESCRIPTION |
|---|---|
conversation_history
|
The conversation history, as a list of
TYPE:
|
conversation_history_id
|
The ID of the conversation history. This should be used when dealing with stateful AI interfaces.
TYPE:
|
conversation_history_system_message
|
The system message of the conversation history.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AIInterfacePayload[Result]
|
The response from the AI interface. |
Source code in conatus/agents/ai_interfaces/base.py
run
¶
run(
*,
conversation_history: Collection[
ConversationAIMessage
] = (),
conversation_history_id: str | None = None,
conversation_history_system_message: (
SystemAIMessage | None
) = None
) -> AIInterfacePayload[Result]
Run the AI interface.
This method abstracts away the logic of interacting with the
AI models, and returns a
AIInterfacePayload
from which the Agent can extract
the result, the cost of the interactions, etc.
If the user wishes to include a previous conversation, they can
provide a list of ConversationAIMessage
objects, and / or a string that will identify the conversation.
| PARAMETER | DESCRIPTION |
|---|---|
conversation_history
|
The conversation history, as a list of
TYPE:
|
conversation_history_id
|
The ID of the conversation history. This should be used when dealing with stateful AI interfaces.
TYPE:
|
conversation_history_system_message
|
The system message of the conversation history.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AIInterfacePayload[Result]
|
The payload of the run. |
Source code in conatus/agents/ai_interfaces/base.py
conatus.agents.ai_interfaces.planning.PlanningAIInterface
¶
PlanningAIInterface(
*,
runtime: Runtime,
task_definition: TaskDefinition,
task_config: ConsolidatedTaskConfig,
run_writer: FileWriter | None = None,
model_config: ModelConfig | ModelConfigTD | None = None,
model_type: ModelType | None = None,
computer_use_mode: bool | None = None,
only_keep_one_computer_use_environment: (
bool | None
) = None,
interface_name: str | None = None,
max_turns: int | None = None,
stop_if_no_tool_calls: bool = False,
**kwargs: ParamType
)
Bases: BaseAIInterfaceWithTask
AI interface for planning a task.
The prompt asks the AI to plan the Task,
and to give some instructions on how to execute it. These instructions can
be used by the ExecutionAIInterface
to execute
the task.
A few notes:
-
We will use, when possible, reasoning models to plan the task. For more information on which model is selected for each provider, see the
default_model_nameimplementation for OpenAI , Anthropic , and Google . -
The prompt is assembled from the following elements:
- The task definition.
- The variables (which, for now, do not include images).
- The action docstrings (since they will not be given as tool schemas).
-
We do not expect any structured output from the AI, so the payload returned by the
runmethod will have a string result.
from conatus import task, browsing_actions
from conatus.io.file import FileWriter
from conatus.agents.ai_interfaces.planning import PlanningAIInterface
from conatus.utils.callable_parsing.runtime import generate_state_and_runtime
@task(actions=[browsing_actions])
def get_hn_headlines_for_day(year: int, month: int, day: int) -> list[str]:
"""Get the Hacker News headlines for a given day."""
pass
# Let's just create a runtime for this example
state, runtime = generate_state_and_runtime(
task=get_hn_headlines_for_day,
args=[2024, 10, 4],
)
# Let's create the AI interface
ai_interface = PlanningAIInterface(
runtime=runtime,
task_definition=get_hn_headlines_for_day.definition,
task_config=get_hn_headlines_for_day.config,
run_writer=FileWriter(),
)
# Let's run the AI interface
payload = ai_interface.run()
print(payload.result)
# > "1. PLAN A -- a. I would first start a browser..."
| PARAMETER | DESCRIPTION |
|---|---|
runtime
|
The runtime state of the agent.
TYPE:
|
task_definition
|
The task definition of the agent.
TYPE:
|
task_config
|
The task configuration of the agent.
TYPE:
|
run_writer
|
The writer used to log run information. If
TYPE:
|
model_config
|
The configuration for the model.
TYPE:
|
model_type
|
The type of model to use for the AI interface. If
TYPE:
|
computer_use_mode
|
Whether to use computer use mode. Defaults to
TYPE:
|
only_keep_one_computer_use_environment
|
Whether to only keep one
computer use environment. Defaults to
TYPE:
|
interface_name
|
The name of the AI interface. Will otherwise be the snake case of the class name.
TYPE:
|
max_turns
|
The maximum number of turns the AI interface can take. Defaults to 1, but can be overridden by the subclass or the user in the constructor.
TYPE:
|
stop_if_no_tool_calls
|
Whether to stop the run if no tool calls are
made. Defaults to
TYPE:
|
kwargs
|
Additional parameters for the AI interface.
TYPE:
|
Source code in conatus/agents/ai_interfaces/base.py
arun
async
¶
arun(
conversation_history: Collection[
ConversationAIMessage
] = (),
conversation_history_id: str | None = None,
conversation_history_system_message: (
SystemAIMessage | None
) = None,
) -> AIInterfacePayload[Result]
Run the AI interface asynchronously.
For more information, see BaseAIInterface.run
.
| PARAMETER | DESCRIPTION |
|---|---|
conversation_history
|
The conversation history, as a list of
TYPE:
|
conversation_history_id
|
The ID of the conversation history. This should be used when dealing with stateful AI interfaces.
TYPE:
|
conversation_history_system_message
|
The system message of the conversation history.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AIInterfacePayload[Result]
|
The response from the AI interface. |
Source code in conatus/agents/ai_interfaces/base.py
run
¶
run(
*,
conversation_history: Collection[
ConversationAIMessage
] = (),
conversation_history_id: str | None = None,
conversation_history_system_message: (
SystemAIMessage | None
) = None
) -> AIInterfacePayload[Result]
Run the AI interface.
This method abstracts away the logic of interacting with the
AI models, and returns a
AIInterfacePayload
from which the Agent can extract
the result, the cost of the interactions, etc.
If the user wishes to include a previous conversation, they can
provide a list of ConversationAIMessage
objects, and / or a string that will identify the conversation.
| PARAMETER | DESCRIPTION |
|---|---|
conversation_history
|
The conversation history, as a list of
TYPE:
|
conversation_history_id
|
The ID of the conversation history. This should be used when dealing with stateful AI interfaces.
TYPE:
|
conversation_history_system_message
|
The system message of the conversation history.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AIInterfacePayload[Result]
|
The payload of the run. |
Source code in conatus/agents/ai_interfaces/base.py
conatus.agents.ai_interfaces.execution.ExecutionAIInterface
¶
ExecutionAIInterface(
*,
runtime: Runtime,
task_definition: TaskDefinition,
task_config: ConsolidatedTaskConfig,
run_writer: FileWriter | None = None,
model_config: ModelConfig | ModelConfigTD | None = None,
model_type: ModelType | None = None,
computer_use_mode: bool = False,
only_keep_one_computer_use_environment: bool = True,
interface_name: str | None = None,
max_turns: int | None = None,
instructions: str | None = None,
stop_if_no_tool_calls: bool = False,
**kwargs: ParamType
)
Bases: BaseAIInterfaceWithTask
AI interface for execution.
This is the main AI interface for executing a Task
. It allows the AI to respond with either
code snippets or tool calls, and adds some preamble to help the AI
understand the task.
One notable aspect of this AI interface is that you can pass instructions
to the constructor. These instructions are used to help the AI understand
the task. This is useful if you've already planned the steps of the task,
and you want to give that information to the AI.
For more information, look at the agents/prompts/execution_dev_message.txt
file, which contains the developer message that is added to the prompt.
| PARAMETER | DESCRIPTION |
|---|---|
runtime
|
The runtime state of the agent.
TYPE:
|
task_definition
|
The task definition of the agent.
TYPE:
|
task_config
|
The task configuration of the agent.
TYPE:
|
run_writer
|
The writer used to log run information. If
TYPE:
|
model_config
|
The configuration for the model.
TYPE:
|
model_type
|
The type of model to use for the AI interface. If
TYPE:
|
computer_use_mode
|
Whether to use computer use mode.
TYPE:
|
only_keep_one_computer_use_environment
|
Whether to only keep one computer use environment.
TYPE:
|
interface_name
|
The name of the AI interface. Will otherwise be the snake case of the class name.
TYPE:
|
max_turns
|
The maximum number of turns the AI interface can take. Defaults to 1, but can be overridden by the subclass or the user in the constructor.
TYPE:
|
instructions
|
The instructions for the AI interface.
TYPE:
|
stop_if_no_tool_calls
|
Whether to stop the run if no tool calls are
made. Defaults to
TYPE:
|
kwargs
|
Additional parameters for the AI interface.
TYPE:
|
Source code in conatus/agents/ai_interfaces/execution.py
instructions
instance-attribute
¶
instructions: str | None = instructions
The instructions for the AI interface.
These instructions are optional, and are used to help the AI understand
the Task. The PlanningAIInterface
was designed
with this in mind.
arun
async
¶
arun(
conversation_history: Collection[
ConversationAIMessage
] = (),
conversation_history_id: str | None = None,
conversation_history_system_message: (
SystemAIMessage | None
) = None,
) -> AIInterfacePayload[Result]
Run the AI interface asynchronously.
For more information, see BaseAIInterface.run
.
| PARAMETER | DESCRIPTION |
|---|---|
conversation_history
|
The conversation history, as a list of
TYPE:
|
conversation_history_id
|
The ID of the conversation history. This should be used when dealing with stateful AI interfaces.
TYPE:
|
conversation_history_system_message
|
The system message of the conversation history.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AIInterfacePayload[Result]
|
The response from the AI interface. |
Source code in conatus/agents/ai_interfaces/base.py
run
¶
run(
*,
conversation_history: Collection[
ConversationAIMessage
] = (),
conversation_history_id: str | None = None,
conversation_history_system_message: (
SystemAIMessage | None
) = None
) -> AIInterfacePayload[Result]
Run the AI interface.
This method abstracts away the logic of interacting with the
AI models, and returns a
AIInterfacePayload
from which the Agent can extract
the result, the cost of the interactions, etc.
If the user wishes to include a previous conversation, they can
provide a list of ConversationAIMessage
objects, and / or a string that will identify the conversation.
| PARAMETER | DESCRIPTION |
|---|---|
conversation_history
|
The conversation history, as a list of
TYPE:
|
conversation_history_id
|
The ID of the conversation history. This should be used when dealing with stateful AI interfaces.
TYPE:
|
conversation_history_system_message
|
The system message of the conversation history.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AIInterfacePayload[Result]
|
The payload of the run. |
Source code in conatus/agents/ai_interfaces/base.py
conatus.agents.ai_interfaces.computer_use.ComputerUseAIInterface
¶
ComputerUseAIInterface(
*,
runtime: Runtime,
task_definition: TaskDefinition,
task_config: ConsolidatedTaskConfig,
run_writer: FileWriter | None = None,
model_config: ModelConfig | ModelConfigTD | None = None,
model_type: ModelType | None = None,
computer_use_mode: bool = False,
only_keep_one_computer_use_environment: bool = True,
interface_name: str | None = None,
max_turns: int | None = None,
instructions: str | None = None,
stop_if_no_tool_calls: bool = False,
**kwargs: ParamType
)
Bases: ExecutionAIInterface
AI interface using native computer use abilities.
| PARAMETER | DESCRIPTION |
|---|---|
runtime
|
The runtime state of the agent.
TYPE:
|
task_definition
|
The task definition of the agent.
TYPE:
|
task_config
|
The task configuration of the agent.
TYPE:
|
run_writer
|
The writer used to log run information. If
TYPE:
|
model_config
|
The configuration for the model.
TYPE:
|
model_type
|
The type of model to use for the AI interface. If
TYPE:
|
computer_use_mode
|
Whether to use computer use mode.
TYPE:
|
only_keep_one_computer_use_environment
|
Whether to only keep one computer use environment.
TYPE:
|
interface_name
|
The name of the AI interface. Will otherwise be the snake case of the class name.
TYPE:
|
max_turns
|
The maximum number of turns the AI interface can take. Defaults to 1, but can be overridden by the subclass or the user in the constructor.
TYPE:
|
instructions
|
The instructions for the AI interface.
TYPE:
|
stop_if_no_tool_calls
|
Whether to stop the run if no tool calls are
made. Defaults to
TYPE:
|
kwargs
|
Additional parameters for the AI interface.
TYPE:
|
Source code in conatus/agents/ai_interfaces/execution.py
arun
async
¶
arun(
conversation_history: Collection[
ConversationAIMessage
] = (),
conversation_history_id: str | None = None,
conversation_history_system_message: (
SystemAIMessage | None
) = None,
) -> AIInterfacePayload[Result]
Run the AI interface asynchronously.
For more information, see BaseAIInterface.run
.
| PARAMETER | DESCRIPTION |
|---|---|
conversation_history
|
The conversation history, as a list of
TYPE:
|
conversation_history_id
|
The ID of the conversation history. This should be used when dealing with stateful AI interfaces.
TYPE:
|
conversation_history_system_message
|
The system message of the conversation history.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AIInterfacePayload[Result]
|
The response from the AI interface. |
Source code in conatus/agents/ai_interfaces/base.py
run
¶
run(
*,
conversation_history: Collection[
ConversationAIMessage
] = (),
conversation_history_id: str | None = None,
conversation_history_system_message: (
SystemAIMessage | None
) = None
) -> AIInterfacePayload[Result]
Run the AI interface.
This method abstracts away the logic of interacting with the
AI models, and returns a
AIInterfacePayload
from which the Agent can extract
the result, the cost of the interactions, etc.
If the user wishes to include a previous conversation, they can
provide a list of ConversationAIMessage
objects, and / or a string that will identify the conversation.
| PARAMETER | DESCRIPTION |
|---|---|
conversation_history
|
The conversation history, as a list of
TYPE:
|
conversation_history_id
|
The ID of the conversation history. This should be used when dealing with stateful AI interfaces.
TYPE:
|
conversation_history_system_message
|
The system message of the conversation history.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AIInterfacePayload[Result]
|
The payload of the run. |