Prerequisites: Read the C++ Framework Overview and Integration Guide first. Your project should already link against
gaia::gaia_core.What You Can Customize
gaia::Agent is designed to be subclassed. All domain-specific behavior lives in two virtual methods:
Two additional hooks are available without subclassing:
Step 1 — Custom System Prompt
getSystemPrompt() returns a string that is injected into the LLM system message before the auto-generated tool list. Use it to:
- Define the agent’s persona and constraints
- Specify the output format you expect
- Guide reasoning style (chain-of-thought, step-by-step, etc.)
The framework automatically appends the tool list and response-format schema after your system prompt. You do not need to describe tools in
getSystemPrompt() — they are injected automatically.Step 2 — Register Tools with Typed Parameters
registerTools() is called by init() once, at construction time. Each tool has:
- A name — used by the LLM to call it
- A description — shown in the LLM system prompt
- A callback —
std::function<json(const json&)> - An optional list of typed parameters — passed as
std::vector<gaia::ToolParameter>
Parameter Types
Example: Multiple Tools with Typed Parameters
The
ToolParameter aggregate is {name, type, required, description}. Optional parameters should have a matching default in your callback (use args.value("key", default_value) from nlohmann/json).Step 3 — Connect a Custom MCP Server
CallconnectMcpServer() after init() to register tools from an external MCP server. This works with any stdio-based MCP server — your own, a third-party package, or a local script.
weather_data are automatically prefixed as mcp_weather_data_<tool_name> and injected into the LLM system prompt alongside your native tools.
Connecting a Local Script
MCP connections use stdio transport (JSON-RPC 2.0 over stdin/stdout). The server subprocess is spawned at
connectMcpServer() time and cleaned up when the agent is destroyed.Disconnect when Done
Step 4 — Combine Native Tools and MCP Tools
Here is a complete agent that uses both native C++ tools and an MCP server in one class:combined_agent.cpp
Step 5 — Tune AgentConfig
AdjustAgentConfig in your makeConfig() static method to match your use case:
Step 6 — Capture Output Programmatically
By default the agent prints to the terminal usingTerminalConsole. You can replace it with SilentConsole (built-in) or a fully custom OutputHandler subclass.
Silent Mode (JSON result only)
Custom Output Capture
OverrideOutputHandler to route output to a log file, a UI widget, or any other sink:
capturing_console.h
Step 7 — Embedding in Your Application
When integrating the agent into a desktop application (WPF, Qt, Electron), you need to run it headless, capture its output programmatically, and keep your UI responsive.Headless Pattern
UseSilentConsole to suppress all terminal output. The only interface is the JSON return value from processQuery():
Background Thread Pattern
SinceprocessQuery() blocks, run it on a background thread and post results to your UI:
Custom OutputHandler for UI Integration
For real-time progress updates in a GUI, implement a customOutputHandler that forwards events to your UI framework:
Thread safety: The
OutputHandler methods are called from the thread running processQuery(). If your callbacks update a GUI, you must post to the UI thread (e.g., QMetaObject::invokeMethod in Qt, Dispatcher.Invoke in WPF, PostMessage in Win32).Multiple Agents
EachAgent instance is independent. You can run multiple agents concurrently on separate threads — each with its own tools, MCP connections, and output handler:
Complete Working Example
Below is a self-contained agent combining all the customization points above. Copy it as a starting point for your own agent:my_custom_agent.cpp
CMakeLists.txt
Summary
Next Steps
C++ Framework Overview
AgentConfig reference and full project structure
Integration Guide
FetchContent, find_package, and shared library integration methods
MCP Client
How the MCP stdio transport works under the hood
Wi-Fi Troubleshooter Agent
Full network diagnostic and auto-fix using registered C++ tools
C++ Source Code
Browse the full implementation on GitHub