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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
//! Durable execution contexts for local development and production engines.
//!
//! [`LocalDurableContext`] is a passthrough implementation for local dev/testing
//! that calls the provider and tools directly without journaling.
//!
//! For production durable execution (Temporal, Restate, Inngest), see the
//! documentation at the bottom of this module for how to implement
//! [`DurableContext`] with those SDKs.
use Arc;
use Duration;
use ToolRegistry;
use ;
/// A passthrough durable context for local development and testing.
///
/// Executes LLM calls and tool calls directly without journaling.
/// No crash recovery, no replay — just direct passthrough.
///
/// This is the default when you do not need durable execution but want
/// a concrete [`DurableContext`] implementation.
// =============================================================================
// Production durable execution implementations
// =============================================================================
//
// ## Temporal
//
// To implement `DurableContext` for Temporal, add `temporal-sdk` as a dependency
// (feature-gated) and wrap the Temporal workflow context:
//
// ```ignore
// use temporal_sdk::WfContext;
//
// pub struct TemporalDurableContext {
// ctx: WfContext,
// tools: Arc<ToolRegistry>,
// }
//
// impl DurableContext for TemporalDurableContext {
// async fn execute_llm_call(
// &self,
// request: CompletionRequest,
// options: ActivityOptions,
// ) -> Result<CompletionResponse, DurableError> {
// let input = serde_json::to_string(&request)
// .map_err(|e| DurableError::ActivityFailed(e.to_string()))?;
// let result = self.ctx
// .activity(ActivityOptions {
// activity_type: "llm_call".to_string(),
// start_to_close_timeout: Some(options.start_to_close_timeout),
// heartbeat_timeout: options.heartbeat_timeout,
// retry_policy: options.retry_policy.map(convert_retry_policy),
// input: vec![input.into()],
// ..Default::default()
// })
// .await
// .map_err(|e| DurableError::ActivityFailed(e.to_string()))?;
// serde_json::from_slice(&result.result)
// .map_err(|e| DurableError::ActivityFailed(e.to_string()))
// }
//
// // ... similar for execute_tool, wait_for_signal, etc.
//
// fn should_continue_as_new(&self) -> bool {
// self.ctx.get_info().is_continue_as_new_suggested()
// }
//
// async fn sleep(&self, duration: Duration) {
// self.ctx.timer(duration).await;
// }
//
// fn now(&self) -> chrono::DateTime<chrono::Utc> {
// // Temporal provides deterministic time during replay
// self.ctx.workflow_time()
// }
// }
// ```
//
// ## Restate
//
// To implement `DurableContext` for Restate, add `restate-sdk` as a dependency
// (feature-gated) and wrap the Restate context:
//
// ```ignore
// use restate_sdk::context::Context;
//
// pub struct RestateDurableContext {
// ctx: Context,
// tools: Arc<ToolRegistry>,
// }
//
// impl DurableContext for RestateDurableContext {
// async fn execute_llm_call(
// &self,
// request: CompletionRequest,
// _options: ActivityOptions,
// ) -> Result<CompletionResponse, DurableError> {
// self.ctx
// .run("llm_call", || async {
// // Direct LLM call here — Restate journals the result
// provider.complete(request).await
// })
// .await
// .map_err(|e| DurableError::ActivityFailed(e.to_string()))
// }
//
// // ... similar for execute_tool, etc.
//
// async fn sleep(&self, duration: Duration) {
// self.ctx.sleep(duration).await;
// }
// }
// ```