Skip to content

Commit bc6ae06

Browse files
Scripted turns can take time; the recordings are typed at a person's pace
A scripted model turn may carry `delay_ms`, so a demo shows the model thinking before it answers; the provider releases its lock before the wait, so parallel sub-agents are not held up. The README's recordings are re-made from a pseudo-terminal with keystrokes typed one at a time and real pauses: the prompt appears as it is typed, the thinking indicator runs while the model works, and the tool lines arrive at the speed they did.
1 parent 8a56612 commit bc6ae06

4 files changed

Lines changed: 20 additions & 8 deletions

File tree

‎crates/provider/Cargo.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ publish.workspace = true
99
workspace = true
1010

1111
[dependencies]
12+
tokio.workspace = true
1213
anyhow.workspace = true
1314
async-trait.workspace = true
1415
gitagent-loader.workspace = true

‎crates/provider/src/scripted.rs‎

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ struct ScriptedTurn {
2525
/// Simulates a provider error: `transient`, `context_overflow` or `fatal`.
2626
#[serde(default)]
2727
error: Option<String>,
28+
/// How long the reply takes, in milliseconds, so a demo shows the
29+
/// model thinking.
30+
#[serde(default)]
31+
delay_ms: u64,
2832
}
2933

3034
#[derive(Debug, Clone, Deserialize)]
@@ -73,14 +77,21 @@ impl ScriptedProvider {
7377
#[async_trait]
7478
impl Provider for ScriptedProvider {
7579
async fn complete(&self, req: &ChatRequest) -> Result<ChatResponse, ProviderError> {
76-
let mut state = self.state.lock().unwrap();
77-
state.requests.push(req.clone());
78-
let index = state.next;
79-
let turn = self
80-
.turns
81-
.get(index)
82-
.ok_or_else(|| ProviderError::Fatal(format!("script ended after {index} turns")))?;
83-
state.next += 1;
80+
let (index, turn) = {
81+
let mut state = self.state.lock().unwrap();
82+
state.requests.push(req.clone());
83+
let index = state.next;
84+
let turn = self
85+
.turns
86+
.get(index)
87+
.ok_or_else(|| ProviderError::Fatal(format!("script ended after {index} turns")))?;
88+
state.next += 1;
89+
(index, turn)
90+
};
91+
// The lock is released, so other callers (parallel sub-agents) go on.
92+
if turn.delay_ms > 0 {
93+
tokio::time::sleep(std::time::Duration::from_millis(turn.delay_ms)).await;
94+
}
8495
if let Some(kind) = &turn.error {
8596
return Err(match kind.as_str() {
8697
"transient" => ProviderError::Transient("scripted".into()),

‎docs/media/console.gif‎

-526 KB
Loading

‎docs/media/parallel.gif‎

914 Bytes
Loading

0 commit comments

Comments
 (0)