12#include <neograph/types.h>
14#include <asio/any_io_executor.hpp>
22namespace sp {
class NativeArchive; }
24namespace neograph::graph {
26struct ProviderOutcomes {
27 mutable std::mutex mutex;
28 std::vector<sp::runtime::Result> values;
29 void add(sp::runtime::Result value) {
30 std::lock_guard lock(mutex);
31 values.push_back(std::move(value));
33 std::vector<sp::runtime::Result> snapshot()
const {
34 std::lock_guard lock(mutex);
43 std::vector<sp::Message> messages;
44 std::uint64_t turns = 0;
45 bool client_calls_ready =
false;
47 mutable std::mutex mutex;
48 std::map<std::string, Entry> entries;
49 Entry get(
const std::string& task)
const {
50 std::lock_guard lock(mutex);
51 const auto found = entries.find(task);
52 return found == entries.end() ? Entry{} : found->second;
54 void set(
const std::string& task, Entry entry) {
55 std::lock_guard lock(mutex);
56 entries.insert_or_assign(task, std::move(entry));
58 std::map<std::string, Entry> snapshot()
const {
59 std::lock_guard lock(mutex);
76 std::shared_ptr<UsageAccumulator>
usage;
77 std::shared_ptr<ProviderOutcomes> provider_outcomes;
78 std::shared_ptr<ProviderLoopHistory> provider_loop_history;
79 std::function<void(
const sp::Event&)> on_provider_event;
80 std::shared_ptr<sp::NativeArchive> native_history_archive;
84 std::shared_ptr<std::atomic_bool> budget_exhausted;
91 std::shared_ptr<CheckpointStore> managed_budget_store;
94 std::optional<std::chrono::steady_clock::time_point>
deadline;
165NEOGRAPH_API std::shared_ptr<ProviderCallBroker> provider_call_broker(
const RunContext& ctx);
167 const std::string& node, std::uint64_t ordinal = 0) {
170 identity.run_id = ctx.
run_id;
173 identity.node_name = node;
175 identity.usage = ctx.
usage;
177 identity.budget_exhausted = ctx.budget_exhausted;
180 identity.managed_budget_store = ctx.managed_budget_store;
186 if (!result)
throw std::runtime_error(
"Provider returned no outcome");
188 ctx.
usage->add(outcome_usage(*result));
189 if (ctx.provider_outcomes) ctx.provider_outcomes->add(result);
194 const RunContext& ctx, asio::awaitable<sp::runtime::Result> operation) {
196 co_return co_await std::move(operation);
200 if (error.outcome())
record_usage(ctx, error.outcome());
Cooperative cancellation primitive for graph runs.
How provider stop reasons reach callers.
Post-dispatch host failure retaining the exact drained provider outcome.
Cross-thread shared memory store (LangGraph Store equivalent).
Graph engine type definitions: channels, edges, nodes, events, and control flow.
StreamMode
Bitfield flags for selecting which events to stream during execution.
Host-owned, invocation-scoped boundary for built-in Core provider calls.
void record_usage(const RunContext &ctx, const sp::runtime::Result &result)
Fold exactly the actual nullable report, never a reservation or charge.
NEOGRAPH_API ToolExecutionContext make_tool_execution_context(const RunContext &ctx)
Populate the mediated Tool execution context for a node invocation: the run's (or attempt's) cancel t...
asio::awaitable< sp::runtime::Result > observe_provider_result(const RunContext &ctx, asio::awaitable< sp::runtime::Result > operation)
Owned failures must not erase the real outcome or its nullable usage.
Per-invocation context for a cooperative asynchronous tool.
std::string effect_task_id
Stable Core node invocation slot, populated by GraphEngine.
Stable Core call identity.
std::uint64_t call_ordinal
Stable per-task ordinal; inner loops assign each provider turn explicitly.
Engine-owned inner-loop continuations, keyed by the compiled task slot.
Per-run dispatch metadata threaded through the engine and executor.
std::shared_ptr< ToolExecutionController > tool_execution_controller
Shared host admission boundary for every tool call in this run.
std::shared_ptr< CancelToken > budget_cancel_token
Shared sibling-cancellation scope for budget-aware nodes.
std::uint64_t cache_execution_id
Engine-assigned identity for this run or resume call.
std::shared_ptr< OwnedManagedBudgetLease > managed_budget_lease
Host-only standalone currency; never recovered from caller JSON.
std::shared_ptr< CancelToken > cancel_token
Operation-scoped cooperative cancellation handle.
std::string run_id
Durable Program run identity used by host-brokered journal effects.
int step
Current super-step index.
bool shared_scheduler
RunMetadata::shared_scheduler: blocking node bodies should not hold the calling executor,...
asio::any_io_executor dispatch_executor
RunMetadata::dispatch_executor: where a node attempt that needs its own worker runs.
std::string thread_id
Mirrors RunConfig::thread_id.
std::uint64_t model_token_budget
Program-supplied token ceiling and terminal signal. Zero/null leave generic Core runs unchanged.
ToolExecutionIdentity tool_execution_identity
Stable host/Program identity copied to each dispatched tool call.
std::optional< std::chrono::steady_clock::time_point > deadline
Absolute monotonic-clock deadline supplied through RunMetadata, when set.
std::shared_ptr< Store > store
Optional cross-thread shared memory.
std::optional< json > resume_value
Value supplied to GraphEngine::resume(), for the one invocation the resume answers,...
StreamMode stream_mode
Mirrors RunConfig::stream_mode.
ToolGate tool_gate
Effective tool policy for this invocation.
std::string resume_interrupt_id
#406: the interrupt resume_value answers, when it answers this invocation's own NodeInterrupt: its Pe...
std::string trace_id
Per-run trace correlator supplied through RunMetadata.
std::shared_ptr< UsageAccumulator > usage
Shared token accounting sink for this run and its subgraphs.