pulsatrix 1.1.0
Loading...
Searching...
No Matches
tool_loop.hpp
Go to the documentation of this file.
1
5#pragma once
6
7#include <functional>
8#include <string>
9#include <vector>
10
13
14namespace pulsatrix::orch {
15
17struct ToolCall {
18 std::string id;
19 std::string name;
21};
22
25 std::string content;
26 bool is_error = false;
27};
28
33using ToolExecutor = std::function<ToolOutcome(const ToolCall&)>;
34
38 int max_turns = 20;
41 std::function<void(const Message&)> on_message;
42};
43
47 std::vector<Message> messages;
50 int turns = 0;
54 bool hit_turn_limit = false;
55};
56
65[[nodiscard]] ToolLoopResult RunToolLoop(Provider& provider, ChatRequest request, const ToolExecutor& execute,
66 const ToolLoopOptions& options = {});
67
68} // namespace pulsatrix::orch
One JSON value: null, a boolean, a number, a string, an array or an object.
Definition json.hpp:22
A model behind an API.
Definition provider.hpp:68
The orchestrator's message format, shared by every LLM provider.
Definition http.hpp:20
std::function< ToolOutcome(const ToolCall &)> ToolExecutor
Runs one tool call. ToolRegistry::executor() provides one; any function works.
Definition tool_loop.hpp:33
ToolLoopResult RunToolLoop(Provider &provider, ChatRequest request, const ToolExecutor &execute, const ToolLoopOptions &options={})
Sends request, runs each tool the model calls with execute, and sends the results back,...
LLM providers: the Anthropic API and OpenAI-compatible servers, behind one interface.
A request to a provider.
Definition message.hpp:99
A provider's answer.
Definition message.hpp:113
One turn of a conversation.
Definition message.hpp:51
Called as a streamed answer arrives. Either may be empty.
Definition provider.hpp:25
One tool call to run.
Definition tool_loop.hpp:17
JsonValue input
Definition tool_loop.hpp:20
std::string id
Definition tool_loop.hpp:18
std::string name
Definition tool_loop.hpp:19
Settings for RunToolLoop().
Definition tool_loop.hpp:36
std::function< void(const Message &)> on_message
Called with each message the loop adds: the model's answers and the tool results.
Definition tool_loop.hpp:41
StreamCallbacks stream
Definition tool_loop.hpp:39
int max_turns
The most requests to make. The loop stops there even if the model wants more tools.
Definition tool_loop.hpp:38
How a tool loop ended.
Definition tool_loop.hpp:45
int turns
Definition tool_loop.hpp:50
ChatResponse last
The last answer.
Definition tool_loop.hpp:49
std::vector< Message > messages
The whole conversation: the request's messages, then everything the loop added.
Definition tool_loop.hpp:47
Usage usage
Usage summed over every request.
Definition tool_loop.hpp:52
bool hit_turn_limit
True if the loop stopped at max_turns while the model still wanted tools.
Definition tool_loop.hpp:54
What a tool returned. An error is reported to the model, which can try again.
Definition tool_loop.hpp:24
bool is_error
Definition tool_loop.hpp:26
std::string content
Definition tool_loop.hpp:25
Tokens used by one request, or summed over a tool loop.
Definition message.hpp:89