ForestHub SDK 0.1.0
C++14 LLM SDK for PC and embedded platforms
Loading...
Searching...
No Matches
runner.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: AGPL-3.0-only
2// Copyright (c) 2026 ForestHub. All rights reserved.
3// For commercial licensing, visit https://github.com/ForestHubAI/fh-sdk
4
5#ifndef FORESTHUB_AGENT_RUNNER_HPP
6#define FORESTHUB_AGENT_RUNNER_HPP
7
10
11#include <memory>
12#include <string>
13#include <vector>
14
20
21namespace foresthub {
22namespace agent {
23
24using json = nlohmann::json;
25
27struct RunResult {
29 std::shared_ptr<Agent> last_agent;
30 int turns = 0;
31};
32
36 std::string error;
37
39 bool HasError() const { return !error.empty(); }
40
44 static RunResultOrError Success(RunResult result) { return {std::move(result), ""}; }
45
49 static RunResultOrError Failure(std::string error_message) {
50 return {foresthub::Optional<RunResult>{}, std::move(error_message)};
51 }
52};
53
55class Runner {
56public:
60 Runner(std::shared_ptr<foresthub::core::LLMClient> client, foresthub::core::ModelID model);
61
64
69 RunResultOrError Run(const std::shared_ptr<Agent>& starting_agent, const std::shared_ptr<core::Input>& input);
70
72 const std::shared_ptr<foresthub::core::LLMClient>& client() const { return client_; }
74 const core::ModelID& default_model() const { return default_model_; }
76 const foresthub::Optional<int>& max_turns() const { return max_turns_; }
77
78private:
79 std::shared_ptr<foresthub::core::LLMClient> client_;
80 core::ModelID default_model_;
81 foresthub::Optional<int> max_turns_;
82
84 struct ExecResult {
85 std::shared_ptr<foresthub::core::Tool> handoff_tool;
87 bool is_handoff = false;
88 std::string error;
89 };
90
95 ExecResult ExecuteFunctionTools(const std::vector<foresthub::core::ToolCallRequest>& requests,
96 const std::shared_ptr<Agent>& agent);
97};
98
99} // namespace agent
100} // namespace foresthub
101
102#endif // FORESTHUB_AGENT_RUNNER_HPP
Agent with instructions, tools, and optional response format.
Runner & WithMaxTurns(int max_turns)
Set the turn limit for agent execution.
RunResultOrError Run(const std::shared_ptr< Agent > &starting_agent, const std::shared_ptr< core::Input > &input)
Execute an agent workflow from the given starting point.
const core::ModelID & default_model() const
Definition runner.hpp:74
const std::shared_ptr< foresthub::core::LLMClient > & client() const
Definition runner.hpp:72
const foresthub::Optional< int > & max_turns() const
Definition runner.hpp:76
Runner(std::shared_ptr< foresthub::core::LLMClient > client, foresthub::core::ModelID model)
Construct a runner with an LLM client and default model.
An ordered list of InputItem elements.
Definition input.hpp:85
Polymorphic input types for chat requests.
Wrapper for nlohmann/json that works around abs macro conflicts.
Agent framework: multi-turn execution with tool calling and handoffs.
std::string ModelID
Unique identifier for an LLM model.
Definition model.hpp:23
Top-level namespace for the ForestHub SDK.
Minimal Optional<T> polyfill for C++14 compatibility.
LLMClient and Provider interfaces for chat operations.
Minimal Optional<T> polyfill for C++14 compatibility.
Definition optional.hpp:21
Result wrapper that holds either a RunResult or an error message.
Definition runner.hpp:34
static RunResultOrError Failure(std::string error_message)
Create a failure result.
Definition runner.hpp:49
static RunResultOrError Success(RunResult result)
Create a successful result.
Definition runner.hpp:44
foresthub::Optional< RunResult > result
Present on success.
Definition runner.hpp:35
bool HasError() const
Check if an error occurred.
Definition runner.hpp:39
std::string error
Non-empty on failure.
Definition runner.hpp:36
Final outcome of an agent execution workflow.
Definition runner.hpp:27
std::shared_ptr< Agent > last_agent
Agent active when execution finished.
Definition runner.hpp:29
json final_output
Output produced by the agent.
Definition runner.hpp:28
int turns
Number of LLM round-trips taken.
Definition runner.hpp:30