Simple Chatbot Example.
#include <agents-cpp/agents/actor_agent.h>
#include <agents-cpp/config_loader.h>
#include <agents-cpp/logger.h>
#include <agents-cpp/tools/tool_registry.h>
#include <iostream>
Task<int> runAgentApp(
int argc,
char* argv[]) {
api_key = config.get("GEMINI_API_KEY", "");
if (api_key.empty() && argc > 1) {
api_key = argv[1];
}
if (api_key.empty()) {
Logger::error(
"1. Create a .env file with GEMINI_API_KEY=your_key, or");
Logger::error(
"2. Set the GEMINI_API_KEY environment variable, or");
Logger::error(
"3. Provide an API key as a command line argument");
co_return EXIT_FAILURE;
}
auto context = std::make_shared<AgentContext>();
auto llm =
createLLM(
"google", api_key,
"gemini-2.0-flash");
llm->setOptions(options);
context->setLLM(llm);
"You are a friendly assistant that helps users find information and answer questions. "
"Use the tools available to you to gather information and provide comprehensive answers. "
"When searching for information, try multiple queries if necessary."
);
});
Logger::info(
"Enter a question or task for the agent (or 'exit' to quit):");
while (true) {
std::getline(std::cin, user_input);
if (user_input == "exit" || user_input == "quit" || user_input == "q") {
break;
}
if (user_input.empty()) {
continue;
}
try {
Logger::info(
"\nFinal Result:\n{}", result[
"answer"].get<String>());
} catch (const std::exception& e) {
}
}
co_return EXIT_SUCCESS;
}
int main(int argc, char* argv[]) {
}
Actor-based agent implementation.
Definition actor_agent.h:31
void setAgentPrompt(const String &agent_prompt)
Set the agent prompt for the agent.
Task< JsonObject > run(const String &task) override
Run the agent with a task using coroutines.
void init() override
Initialize the agent.
void setStatusCallback(std::function< void(const String &)> callback)
Set a callback for status updates.
static ConfigLoader & getInstance()
Get the singleton instance of ConfigLoader.
@ INFO
Info logging level.
Definition logger.h:40
static void error(fmt::format_string< Args... > fmt, Args &&... args)
Log a message at error level.
Definition logger.h:124
static void init(Level level=Level::INFO)
Initialize the logger.
static void info(fmt::format_string< Args... > fmt, Args &&... args)
Log a message at info level.
Definition logger.h:104
Standard C++20 coroutine-based Task implementation (no external deps)
Definition coroutine_utils.h:38
Framework Namespace.
Definition agent.h:18
nlohmann::json JsonObject
JSON object type.
Definition types.h:39
std::shared_ptr< LLMInterface > createLLM(const String &provider, const String &api_key, const String &model="")
Factory function to create a specific LLM provider.
std::string String
String type.
Definition types.h:27
T blockingWait(Task< T > &&task)
Helper to run a coroutine and get the result synchronously.
Definition coroutine_utils.h:496
Options for LLM API calls.
Definition llm_interface.h:25
double temperature
The temperature of the LLM.
Definition llm_interface.h:29