AgentRuntime
The AgentRuntime class is a high-level wrapper around ChatObject that provides a reusable agent operation interface.
This class encapsulates the complexity of ChatObject and provides a simplified API for agent interactions. It maintains session state, configuration, and strategy settings, making it a reusable object for multiple agent operations within the same context.
Properties
strategy(type[AgentStrategy]): Agent strategy class used for executionsession_id(str): Session ID for the agentslot(BackendSlots): Backend slots providing memory and ability backendspreset(ModelPreset): Model preset configurationconfig(AmritaConfig): Amrita configuration objecttrain(Message[str]): Training data (system prompts)template(Template): Jinja2 template used to render system role message
Constructor Parameters
config(AmritaConfig): Amrita configuration object containing global configuration settingspreset(ModelPreset): Model preset configuration defining basic model parameters and settingstrain(dict[str, str] | Message[str]): System prompt for the agent (dict or Message object)strategy(type[AgentStrategy], optional): Agent strategy class, defaults to ReActAgentStrategytemplate(Template | str, optional): Jinja2 template used to render the system prompt, defaults to DEFAULT_TEMPLATEsession_id(str | None, optional): Session identifier string. If None, a new UUID-based ID is generated. The session_id is passed to every ChatObject created by this runtime, allowing the Backend to isolate memory and abilities per sessionbackend(BackendSlots | None, optional): Backend slots providing memory and ability backends. If None, aLegacyBackendis used for both slots, which stores data in global in-process containers
Methods
set_strategy(strategy)
Set the agent strategy to be used for execution.
Parameters:
strategy(type[AgentStrategy]): The agent strategy to be used for execution
get_chatobject(input, **kwargs)
Get a chat object for a specific interaction.
Parameters:
input(USER_INPUT): Input from the user**kwargs: Additional keyword arguments passed to ChatObject constructor
Returns: ChatObject - A configured ChatObject instance ready for execution
Usage Example
python
from amrita_core import create_agent
# Create an agent using the factory function
agent = create_agent(
"https://api.example.com",
"your-api-key",
model="gpt-4",
model_config={"temperature": 0.7},
)
# Get a chat object for interaction
chat = agent.get_chatobject("Hello, what can you do?")
# Execute the interaction
async with chat.begin():
response = await chat.full_response()
await chat # Wait for the task to finish before exiting
print(response)