Entropic 2.11.1
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 <string>
20#include <vector>
21
22namespace entropic {
23
29 std::string content;
30 std::string tool_calls_json;
31 std::string finish_reason;
32};
33
43public:
52 ResponseGenerator(const InferenceInterface& inference,
53 const LoopConfig& loop_config,
54 EngineCallbacks& callbacks,
55 GenerationEvents events);
56
65
74 bool is_response_complete(const std::string& content,
75 const std::string& tool_calls_json);
76
77private:
84 void lock_tier_if_needed(LoopContext& ctx);
85
94 GenerateResult generate_streaming(LoopContext& ctx);
95
103 GenerateResult generate_batch(LoopContext& ctx);
104
122 int dispatch_batch_generate(
123 const std::string& msgs_json,
124 const std::string& params_json,
125 char** result_json);
126
140 std::pair<std::string, std::string> prepare_prompts(
141 LoopContext& ctx, const char* mode);
142
151 std::string handle_pause(LoopContext& ctx,
152 const std::string& partial);
153
160 static std::string serialize_messages(
161 const std::vector<Message>& messages);
162
170 std::string build_params_json(const std::string& tier);
171
196 std::vector<Message> inject_engine_state_reminder(
197 const std::vector<Message>& messages,
198 const LoopContext& ctx);
199
200 InferenceInterface inference_;
201 LoopConfig loop_config_;
202 EngineCallbacks& callbacks_;
203 GenerationEvents events_;
204 HookInterface hooks_;
209 TokenCallback stream_observer_ = nullptr;
210 void* stream_observer_data_ = nullptr;
211
216 void (*state_observer_)(int, void*) = nullptr;
217 void* state_observer_data_ = nullptr;
218
219public:
226 void set_hooks(const HookInterface& hooks) { hooks_ = hooks; }
227
241 void set_stream_observer(TokenCallback observer, void* user_data) {
242 stream_observer_ = observer;
243 stream_observer_data_ = user_data;
244 }
245
252 TokenCallback stream_observer() const { return stream_observer_; }
253
267 void (*observer)(int, void*), void* user_data) {
268 state_observer_ = observer;
269 state_observer_data_ = user_data;
270 }
271
278 void* stream_observer_data() const { return stream_observer_data_; }
279};
280
281} // 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).
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.