Entropic 2.14.3
Local-first agentic inference engine
Loading...
Searching...
No Matches
response_generator.h
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
12#pragma once
13
18
19#include <atomic>
20#include <string>
21#include <thread>
22#include <vector>
23
24namespace entropic {
25
31 std::string content;
32 std::string tool_calls_json;
33 std::string finish_reason;
34};
35
45public:
55 const LoopConfig& loop_config,
56 EngineCallbacks& callbacks,
57 GenerationEvents events);
58
67
76 bool is_response_complete(const std::string& content,
77 const std::string& tool_calls_json);
78
79private:
86 void lock_tier_if_needed(LoopContext& ctx);
87
96 GenerateResult generate_streaming(LoopContext& ctx);
97
105 GenerateResult generate_batch(LoopContext& ctx);
106
124 int dispatch_batch_generate(
125 const std::string& msgs_json,
126 const std::string& params_json,
127 char** result_json);
128
137 std::thread spawn_cancel_poller(int& cancel_int,
138 std::atomic<bool>& done) const;
139
153 std::pair<std::string, std::string> prepare_prompts(
154 LoopContext& ctx, const char* mode);
155
164 std::string handle_pause(LoopContext& ctx,
165 const std::string& partial);
166
173 static std::string serialize_messages(
174 const std::vector<Message>& messages);
175
183 std::string build_params_json(const std::string& tier,
184 const std::string& session_key = "");
185
210 std::vector<Message> inject_engine_state_reminder(
211 const std::vector<Message>& messages,
212 const LoopContext& ctx);
213
214 InferenceInterface inference_;
215 LoopConfig loop_config_;
216 EngineCallbacks& callbacks_;
217 GenerationEvents events_;
218 HookInterface hooks_;
223 TokenCallback stream_observer_ = nullptr;
224 void* stream_observer_data_ = nullptr;
225
230 void (*state_observer_)(int, void*) = nullptr;
231 void* state_observer_data_ = nullptr;
232
233public:
240 void set_hooks(const HookInterface& hooks) { hooks_ = hooks; }
241
255 void set_stream_observer(TokenCallback observer, void* user_data) {
256 stream_observer_ = observer;
257 stream_observer_data_ = user_data;
258 }
259
266 TokenCallback stream_observer() const { return stream_observer_; }
267
281 void (*observer)(int, void*), void* user_data) {
282 state_observer_ = observer;
283 state_observer_data_ = user_data;
284 }
285
292 void* stream_observer_data() const { return stream_observer_data_; }
293};
294
295} // namespace entropic
Handles model response generation, tier routing, pause/injection.
GenerateResult generate_response(LoopContext &ctx)
Generate model response, routing tier first if needed.
void set_stream_observer(TokenCallback observer, void *user_data)
Set the global stream observer.
bool is_response_complete(const std::string &content, const std::string &tool_calls_json)
Check if the last response indicates completion.
void set_hooks(const HookInterface &hooks)
Set the hook dispatch interface.
void set_state_observer(void(*observer)(int, void *), void *user_data)
Set the persistent state-transition observer.
void * stream_observer_data() const
Get the observer's user_data pointer.
TokenCallback stream_observer() const
Get the registered stream observer callback.
Types for the agentic loop engine.
Hook dispatch interface injected into engine subsystems.
Function pointer types for core-to-inference communication.
Activate model on GPU (WARM → ACTIVE).
@ optional
optional: every escape asks the host's path approver
@ tier
The TIER's identity frontmatter grammar: stem (gh#154).
void(*)(const char *, size_t, void *) TokenCallback
Token callback type matching the C API signature.
Streaming filter that strips a model family's reasoning blocks.
Callback function pointer types for engine events.
Result of a generate_response call.
std::string tool_calls_json
Tool calls as JSON (empty if none)
std::string finish_reason
"stop", "length", "interrupted"
std::string content
Cleaned response content.
Atomic flags for interrupt/pause signaling.
Configuration for the agentic loop.
Mutable state carried through the agentic loop.