NeoGraph 0.10.0
A C++17 Graph Agent Engine Library — LangGraph for C++
Loading...
Searching...
No Matches
neograph::llm::Agent Class Reference

Standalone ReAct agent that loops between LLM calls and tool execution. More...

#include <agent.h>

Public Member Functions

 Agent (std::shared_ptr< Provider > provider, std::vector< std::unique_ptr< Tool > > tools, const std::string &instructions="", const std::string &model="")
 Construct an agent with a provider and tools.
 
ChatCompletion complete (const std::vector< ChatMessage > &messages)
 Perform a single LLM completion (no tool loop).
 
std::string run (std::vector< ChatMessage > &messages, int max_iterations=10)
 Run the agent loop until completion.
 
std::string run_stream (std::vector< ChatMessage > &messages, const StreamCallback &on_chunk, int max_iterations=10)
 Run the agent loop with streaming token output.
 

Detailed Description

Standalone ReAct agent that loops between LLM calls and tool execution.

The agent sends messages to the LLM, checks for tool calls, executes them, feeds results back, and repeats until the LLM produces a final text response or the iteration limit is reached.

auto agent = Agent(provider, std::move(tools), "You are a helpful assistant.");
std::vector<ChatMessage> messages = {{.role = "user", .content = "What's 2+2?"}};
std::string reply = agent.run(messages);
Standalone ReAct agent that loops between LLM calls and tool execution.
Definition agent.h:37
See also
neograph::graph::create_react_graph for the graph-based equivalent.

Definition at line 37 of file agent.h.

Constructor & Destructor Documentation

◆ Agent()

neograph::llm::Agent::Agent ( std::shared_ptr< Provider provider,
std::vector< std::unique_ptr< Tool > >  tools,
const std::string &  instructions = "",
const std::string &  model = "" 
)

Construct an agent with a provider and tools.

Parameters
providerLLM provider for making completions.
toolsVector of tools available to the agent (ownership transferred).
instructionsOptional system prompt prepended to the conversation.
modelOptional model name override (empty = use provider default).

Member Function Documentation

◆ complete()

ChatCompletion neograph::llm::Agent::complete ( const std::vector< ChatMessage > &  messages)

Perform a single LLM completion (no tool loop).

Parameters
messagesConversation history (not modified).
Returns
The full completion response.

◆ run()

std::string neograph::llm::Agent::run ( std::vector< ChatMessage > &  messages,
int  max_iterations = 10 
)

Run the agent loop until completion.

Iterates between LLM calls and tool execution until the LLM produces a response with no tool calls, or max_iterations is reached.

Parameters
[in,out]messagesConversation history (modified in-place with new messages).
max_iterationsMaximum number of LLM call iterations (default: 10).
Returns
The final text response from the LLM.

◆ run_stream()

std::string neograph::llm::Agent::run_stream ( std::vector< ChatMessage > &  messages,
const StreamCallback on_chunk,
int  max_iterations = 10 
)

Run the agent loop with streaming token output.

Same as run(), but streams the final response tokens via the callback.

Parameters
[in,out]messagesConversation history (modified in-place).
on_chunkCallback invoked per token during the final LLM response.
max_iterationsMaximum LLM call iterations (default: 10).
Returns
The final text response.

The documentation for this class was generated from the following file: