NeoGraph 0.10.0
A C++17 Graph Agent Engine Library — LangGraph for C++
Loading...
Searching...
No Matches
agent.h
Go to the documentation of this file.
1
9#pragma once
10
11#include <neograph/api.h>
12#include <neograph/provider.h>
13#include <neograph/tool.h>
14#include <functional>
15#include <memory>
16#include <string>
17#include <unordered_map>
18#include <vector>
19
20namespace neograph::llm {
21
37class NEOGRAPH_API Agent {
38 public:
46 Agent(std::shared_ptr<Provider> provider,
47 std::vector<std::unique_ptr<Tool>> tools,
48 const std::string& instructions = "",
49 const std::string& model = "");
50
51 // Move-only — `tools_` is `vector<unique_ptr<Tool>>`. Explicit
52 // declarations are required because Agent is NEOGRAPH_API and MSVC
53 // eagerly instantiates all special members for dll-exported classes
54 // (the implicit copy-assign tries to copy the vector → deleted →
55 // C2280). GCC/Clang only instantiate on use, so the bug was Windows-
56 // only and silently broke the wheel build.
57 Agent(const Agent&) = delete;
58 Agent& operator=(const Agent&) = delete;
59 Agent(Agent&&) noexcept = default;
60 Agent& operator=(Agent&&) noexcept = default;
61 ~Agent() = default;
62
73 std::string run(std::vector<ChatMessage>& messages,
74 int max_iterations = 10);
75
86 std::string run_stream(std::vector<ChatMessage>& messages,
87 const StreamCallback& on_chunk,
88 int max_iterations = 10);
89
95 ChatCompletion complete(const std::vector<ChatMessage>& messages);
96
97 private:
98 std::shared_ptr<Provider> provider_;
99 std::vector<std::unique_ptr<Tool>> tools_;
104 std::unordered_map<std::string, Tool*> tools_by_name_;
105 std::string instructions_;
106 std::string model_;
107
108 void ensure_system_message(std::vector<ChatMessage>& messages);
109 std::vector<ChatTool> get_tool_definitions() const;
110};
111
112} // namespace neograph::llm
NEOGRAPH_API export/import macro for shared-library builds.
Abstract base class for LLM providers.
Definition provider.h:127
Abstract base class for tools that agents can call.
Definition tool.h:28
Standalone ReAct agent that loops between LLM calls and tool execution.
Definition agent.h:37
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.
Abstract LLM provider interface.
std::function< void(const std::string &chunk)> StreamCallback
Callback invoked per token during streaming completion.
Definition provider.h:52
LLM completion response including the message and token usage.
Definition types.h:60
A message in the conversation history.
Definition types.h:36
Tool definition metadata sent to the LLM.
Definition types.h:51
Abstract tool interface for callable functions.