Build a credential-free client, session, stateful tool, and tracers.
#include <cstdlib>
#include <iostream>
#include <memory>
#include <string>
#include <utility>
using namespace neuralplus;
namespace {
std::string latest_tool_output;
if (message.role() == Role::tool) {
latest_tool_output = message.text();
}
}
if (!latest_tool_output.empty()) {
"The final tool output is " + latest_tool_output + ".")};
response.provider_model = "local-demo";
return response;
}
first.
id =
"increment-1";
first.
name =
"increment";
second.
id =
"increment-2";
second.
name =
"increment";
Message::assistant("I will update the counter.", {first, second})};
response.provider_model = "local-demo";
return response;
}
}
int main() {
spec.
description =
"Atomically increment this session's counter.";
{"type", "object"},
{"properties", {{"delta", {{"type", "integer"}}}}},
{"required", {"delta"}},
};
auto increment = std::make_shared<FunctionTool>(
std::move(spec),
const int delta = arguments.at("delta").get<int>();
const int value = context.
state().update<int>(
"counter", 0,
[delta](int current) { return current + delta; });
return ToolOutput::json({{"counter", value}});
});
options.
tools = {increment};
options.tracers = {std::make_shared<ConsoleTracer>()};
client.generate(session, "Increment the counter by two and three.");
const int counter = session.
state().
get<
int>(
"counter").value_or(-1);
std::cout << "Session counter: " << counter << '\n';
<<
", tool calls: " << response.
tool_calls <<
'\n';
return counter == 5 ? EXIT_SUCCESS : EXIT_FAILURE;
}
Definition client.hpp:128
A valid conversation message with one normalized role.
Definition types.hpp:208
std::string text() const
Concatenates text parts without discarding non-text parts from the message.
std::optional< T > get(std::string_view key) const
Returns a copy of a typed value, or no value when the key is absent.
Definition session.hpp:44
Definition session.hpp:106
SessionState & state() noexcept
Returns the session-scoped generic cache.
SessionState & state() const noexcept
Returns the session-scoped state available to the tool.
Immutable snapshot passed to one provider round.
Definition types.hpp:372
std::vector< Message > messages
Complete normalized transcript snapshot.
Definition types.hpp:383
Normalized response returned by both one provider round and the full tool loop.
Definition types.hpp:393
FinishReason finish_reason
Normalized provider stop reason.
Definition types.hpp:401
std::size_t tool_calls
Tool invocations completed by the public generate call.
Definition types.hpp:416
Message message
Assistant message returned by the provider.
Definition types.hpp:398
std::size_t model_rounds
Provider rounds completed by the public generate call.
Definition types.hpp:413
Dependencies and behavior shared by all AIClient implementations.
Definition client.hpp:25
Tools tools
Immutable set of tools advertised to the configured model.
Definition client.hpp:27
bool tools
Supports function/tool declarations.
Definition types.hpp:308
bool parallel_tool_calls
May request more than one tool in a provider round.
Definition types.hpp:311
Data-driven model description; no C++ subclass is needed per model name.
Definition types.hpp:315
Provider provider
Provider protocol used by the configured client.
Definition types.hpp:317
ModelCapabilities capabilities
Discoverable features used for early validation.
Definition types.hpp:326
std::string display_name
Optional user-interface label.
Definition types.hpp:323
std::string id
Provider model identifier.
Definition types.hpp:320
nlohmann::json JsonValue
Definition types.hpp:26