Agents 1.4.0
Edge AI Agents SDK
Loading...
Searching...
No Matches
agents::Context Class Reference

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

#include <context.h>

Public Member Functions

 Context ()
 Default constructor for Context.
 ~Context ()=default
 Default destructor for Context.
void setLLM (std::shared_ptr< LLMInterface > llm)
 Set the LLM to use.
std::shared_ptr< LLMInterfacegetLLM () const
 Get the LLM.
void setSystemPrompt (const std::string &system_prompt)
 Set the system prompt.
const std::string & getSystemPrompt () const
 Get the system prompt.
void registerToolRegistry (tools::ToolRegistry &registry)
 Register tools from a ToolRegistry.
void registerTool (std::shared_ptr< Tool > tool)
 Register a tool.
std::shared_ptr< ToolgetTool (const std::string &name) const
 Get a tool by name.
std::vector< std::shared_ptr< Tool > > getTools () const
 Get all tools.
Task< ToolResultexecuteTool (const std::string &name, const JsonObject &params)
 Execute a tool by name using coroutines.
std::shared_ptr< MemorygetMemory () 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 std::string user_message, const std::vector< std::string > uris_or_data={})
 Multimodal chat completion with the current context.
Task< LLMResponsechatWithTools (const std::string user_message, const std::vector< std::string > uris_or_data={})
 Multimodal chat completion with tools.
AsyncGenerator< std::string > streamChat (const std::string user_message, const std::vector< std::string > uris_or_data={})
 Multimodal streaming chat (accepts one or more media URIs or data strings).
AsyncGenerator< std::string > streamChatWithTools (const std::string user_message, const std::vector< std::string > uris_or_data={})
 Multimodal streaming chat with tools.

Detailed Description

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

Member Function Documentation

◆ addMessage()

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

Add a message to the conversation history.

Parameters
messageThe message to add

◆ chat()

Task< LLMResponse > agents::Context::chat ( const std::string user_message,
const std::vector< std::string > uris_or_data = {} )

Multimodal chat completion with the current context.

Parameters
user_messageThe user message to send
uris_or_dataOptional URIs or data to use
Returns
The LLM response

◆ chatWithTools()

Task< LLMResponse > agents::Context::chatWithTools ( const std::string user_message,
const std::vector< std::string > uris_or_data = {} )

Multimodal chat completion with tools.

Parameters
user_messageThe user message to send
uris_or_dataOptional URIs or data to use
Returns
The LLM response

◆ executeTool()

Task< ToolResult > agents::Context::executeTool ( const std::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::Context::getLLM ( ) const

Get the LLM.

Returns
The LLM

◆ getMemory()

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

Get the memory.

Returns
The memory

◆ getMessages()

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

Get all messages in the conversation history.

Returns
The messages

◆ getSystemPrompt()

const std::string & agents::Context::getSystemPrompt ( ) const

Get the system prompt.

Returns
The system prompt

◆ getTool()

std::shared_ptr< Tool > agents::Context::getTool ( const std::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::Context::getTools ( ) const

Get all tools.

Returns
The tools

◆ registerTool()

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

Register a tool.

Parameters
toolThe tool to register

◆ registerToolRegistry()

void agents::Context::registerToolRegistry ( tools::ToolRegistry & registry)

Register tools from a ToolRegistry.

Parameters
registryThe ToolRegistry to register from

◆ setLLM()

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

Set the LLM to use.

Parameters
llmThe LLM to use

◆ setSystemPrompt()

void agents::Context::setSystemPrompt ( const std::string & system_prompt)

Set the system prompt.

Parameters
system_promptThe system prompt to use

◆ streamChat()

AsyncGenerator< std::string > agents::Context::streamChat ( const std::string user_message,
const std::vector< std::string > uris_or_data = {} )

Multimodal streaming chat (accepts one or more media URIs or data strings).

Parameters
user_messageThe user message to send
uris_or_dataOptional URIs or data to use
Returns
The LLM response

◆ streamChatWithTools()

AsyncGenerator< std::string > agents::Context::streamChatWithTools ( const std::string user_message,
const std::vector< std::string > uris_or_data = {} )

Multimodal streaming chat with tools.

Parameters
user_messageThe user message to send
uris_or_dataOptional URIs or data to use
Returns
The LLM response