Agents 0.0.2
Edge AI Agents SDK
Loading...
Searching...
No Matches
AgentContext Class Reference

Context for an agent, containing tools, LLM, and memory. More...

#include <agent_context.h>

Public Member Functions

void setLLM (std::shared_ptr< LLMInterface > llm)
 Set the LLM to use.
 
std::shared_ptr< LLMInterfacegetLLM () const
 Get the LLM.
 
void setSystemPrompt (const String &system_prompt)
 Set the system prompt.
 
const StringgetSystemPrompt () const
 Get the system prompt.
 
void registerTool (std::shared_ptr< Tool > tool)
 Register a tool.
 
std::shared_ptr< ToolgetTool (const String &name) const
 Get a tool by name.
 
std::vector< std::shared_ptr< Tool > > getTools () const
 Get all tools.
 
Task< ToolResultexecuteTool (const String &name, const JsonObject &params)
 Execute a tool by name using coroutines.
 
std::shared_ptr< Memory > getMemory () const
 Get the memory.
 
void addMessage (const Message &message)
 Add a message to the conversation history.
 
std::vector< MessagegetMessages () const
 Get all messages in the conversation history.
 
Task< LLMResponsechat (const String &user_message)
 Run a chat completion with the current context using coroutines.
 
Task< LLMResponsechatWithTools (const String &user_message)
 Run a chat completion with tools using coroutines.
 
AsyncGenerator< StringstreamChat (const String &user_message)
 Stream chat results with AsyncGenerator.
 

Detailed Description

Context for an agent, containing tools, LLM, and memory.

Member Function Documentation

◆ addMessage()

void agents::AgentContext::addMessage ( const Message & message)

Add a message to the conversation history.

Parameters
messageThe message to add

◆ chat()

Task< LLMResponse > agents::AgentContext::chat ( const String & user_message)

Run a chat completion with the current context using coroutines.

Parameters
user_messageThe user message to send
Returns
The LLM response

◆ chatWithTools()

Task< LLMResponse > agents::AgentContext::chatWithTools ( const String & user_message)

Run a chat completion with tools using coroutines.

Parameters
user_messageThe user message to send
Returns
The LLM response

◆ executeTool()

Task< ToolResult > agents::AgentContext::executeTool ( const String & name,
const JsonObject & params )

Execute a tool by name using coroutines.

Parameters
nameThe name of the tool to execute
paramsThe parameters to pass to the tool
Returns
The result of the tool execution

◆ getLLM()

std::shared_ptr< LLMInterface > agents::AgentContext::getLLM ( ) const

Get the LLM.

Returns
The LLM

◆ getMemory()

std::shared_ptr< Memory > agents::AgentContext::getMemory ( ) const

Get the memory.

Returns
The memory

◆ getMessages()

std::vector< Message > agents::AgentContext::getMessages ( ) const

Get all messages in the conversation history.

Returns
The messages

◆ getSystemPrompt()

const String & agents::AgentContext::getSystemPrompt ( ) const

Get the system prompt.

Returns
The system prompt

◆ getTool()

std::shared_ptr< Tool > agents::AgentContext::getTool ( const String & name) const

Get a tool by name.

Parameters
nameThe name of the tool to get
Returns
Pointer to tool

◆ getTools()

std::vector< std::shared_ptr< Tool > > agents::AgentContext::getTools ( ) const

Get all tools.

Returns
The tools

◆ registerTool()

void agents::AgentContext::registerTool ( std::shared_ptr< Tool > tool)

Register a tool.

Parameters
toolThe tool to register

◆ setLLM()

void agents::AgentContext::setLLM ( std::shared_ptr< LLMInterface > llm)

Set the LLM to use.

Parameters
llmThe LLM to use

◆ setSystemPrompt()

void agents::AgentContext::setSystemPrompt ( const String & system_prompt)

Set the system prompt.

Parameters
system_promptThe system prompt to use

◆ streamChat()

AsyncGenerator< String > agents::AgentContext::streamChat ( const String & user_message)

Stream chat results with AsyncGenerator.

Parameters
user_messageThe user message to send
Returns
The LLM response