1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
//! Optional execution components over the Causa material kernel.
//!
//! [`TurnRunner`] owns only a gateway and [`ToolExecutor`]. Each run consumes
//! a context and returns it in [`TurnOutcome`], with any uncommitted tool batch.
//! Model identity, generation, limits, optional preparation and observation
//! are explicit per-run choices. Both entry points share the same loop.
//!
//! [`ToolExecutor::bind`] fixes the actual tool surface and targets before
//! preparation. Processing owns controlled collection of started calls;
//! the runner validates and atomically appends results only after success.
//! Unknown results are committed and stop further model rounds.
//!
//! # Policy surface
//!
//! | Choice | Default and owner |
//! |---|---|
//! | Model rounds / tool declarations | [`TurnLimits`]: 10 / 64 |
//! | Model retries | None; optional [`RetryingGateway`] around the chosen gateway |
//! | Material preparation | None; use the current context frame |
//! | Observation | None; an optional synchronous borrowed callback |
//! | Tool processing | Executor-owned ordered before/after processors |
//! | Tool dispatch | Every pending call of a batch at once on the caller's task: concurrent, not parallel, unbounded, nothing spawned; panic becomes failed result |
//! | Tool timeout | None; local timeout becomes unknown outcome |
//! | Stopping a tool | At the tool's next yield point; a tool that blocks the thread is not stopped or timed out (see [`Tool`](causa_kernel::Tool)) |
//! | Unknown outcomes | Commit the successful batch, then stop |
//! | Stop after a batch finished processing | Commit its results, then report the stop |
//! | Output retention and persistence | Caller-owned policies and storage |
//!
//! # Optional retries
//!
//! Retries are off by default: the runner makes one logical gateway call per
//! round and the first error ends it. A host that wants bounded retries wraps
//! its gateway in [`RetryingGateway`] with a [`RetryPolicy`]. The wrapper
//! is an ordinary [`causa_kernel::ModelGateway`]: every attempt sends the
//! same request, only `Transient` and `TimedOut` failures are retried, waits
//! stay inside the caller's cancellation and deadline, and the call is never
//! retried once any stream delta has been yielded. Only the final error
//! reaches the runner.
//!
//! The runner does not interpret imported tool declarations as work to resume.
//! It creates work only from the current model output. Session admission,
//! history, input queues, retries, budget strategies and observation storage
//! belong to callers. Dropping a run future or panicking bypasses the normal
//! material-return guarantee; stopping local waits cannot undo remote effects.
//!
//! # Target path of one model call
//!
//! ```text
//! host
//! TurnRunner (causa-runtime), per round:
//! ToolExecutor::bind -> ToolSurface
//! ContextPreparer (host, opt.) -> ContextFrame
//! build ModelRequest { invocation_id, frame, model, tool_surface, generation, cache }
//! ModelGateway::invoke | stream <- contract, causa-kernel
//! [optional] retry wrapper (causa-runtime) same request each attempt; waits
//! retry_delay or backs off; never
//! retries after a delta was yielded
//! HTTP gateway (causa-provider)
//! MediaResolver -> MediaSet
//! render (causa-protocol) frame -> wire JSON; rejects unsupported
//! generation options before any HTTP
//! send (reqwest), raced against CallControl
//! status / headers -> ModelInvokeErrorKind, retry_delay
//! parse | StreamDecoder (causa-protocol) wire -> ModelOutput, one stop
//! mapping per protocol for both entry points
//! <- ModelOutput { response, usage, stop_reason, raw_stop_reason, reasoning }
//! stop policy: continue on EndTurn / ToolUse; any other reason returns an
//! interruption that carries the uncommitted output
//! commit: ModelResponse::to_blocks -> Context
//! ```
//!
//! Ownership by layer: the kernel defines the shapes and the trait; the
//! protocol crate owns every wire rule; the provider crate owns HTTP and the
//! classification of HTTP outcomes; the runtime owns ordering, stop policy and
//! the optional retry; the host owns preparation, limits and persistence.
pub use ToolBridge;
pub use ;
pub use ;
pub use ;
pub use ;
pub use new_block_id;
pub use ;