Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ repository = "https://github.com/cppalliance/runvil-workshop"
# Workshop links in. All three name one commit, because two commits would
# be two copies of every type the crates share. `version` beside `git`
# keeps cargo-deny's wildcard check quiet.
runvil = { version = "0.3.0", git = "https://github.com/cppalliance/runvil-harness", rev = "6efe4ad7c4d801adebb5b292e4ee7690581c5d35" }
harness-gateway-client = { version = "0.3.0", git = "https://github.com/cppalliance/runvil-harness", rev = "6efe4ad7c4d801adebb5b292e4ee7690581c5d35" }
plugin-mcp = { version = "0.3.0", git = "https://github.com/cppalliance/runvil-harness", rev = "6efe4ad7c4d801adebb5b292e4ee7690581c5d35" }
runvil = { version = "0.3.0", git = "https://github.com/cppalliance/runvil-harness", rev = "ee89d0882ec8cecfcd0159c7f61c6741fceef612" }
harness-gateway-client = { version = "0.3.0", git = "https://github.com/cppalliance/runvil-harness", rev = "ee89d0882ec8cecfcd0159c7f61c6741fceef612" }
plugin-mcp = { version = "0.3.0", git = "https://github.com/cppalliance/runvil-harness", rev = "ee89d0882ec8cecfcd0159c7f61c6741fceef612" }
# The safe layer over the C Plugin contract, version 0.6, from its own
# repository, pinned by commit. Only the library Plugin crates under
# `crates/workshop/` name it, for `export_plugin!`. The commit is the one
Expand Down
10 changes: 6 additions & 4 deletions crates/workshop/agents/src/conversation-run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

use std::sync::Arc;

use runvil::harness::{RunRecorder, display_chain};
use runvil::harness::{IntoShared, RunRecorder, display_chain};
use runvil::ids::RoundId;
use runvil::{Error, Harness, Host, Prompt, RunReport, RunSetup};

Expand All @@ -20,10 +20,12 @@ const CANCELED: &str = "the agent run was canceled";
impl Conversation {
/// The recorder the run writes through: every call goes on to
/// `inner`, and each event `inner` accepted reaches this
/// conversation.
/// conversation. `inner` is taken in each form in which a run's
/// setup takes a recorder: the recorder itself, an `Arc` of it, or
/// an `Arc<dyn RunRecorder>`.
#[must_use]
pub fn recorder(&self, inner: Arc<dyn RunRecorder>) -> Arc<dyn RunRecorder> {
Arc::new(ConversationRecorder::new(self.clone(), inner))
pub fn recorder(&self, inner: impl IntoShared<dyn RunRecorder>) -> Arc<dyn RunRecorder> {
Arc::new(ConversationRecorder::new(self.clone(), inner.into_shared()))
}

/// Parses the agent `name` on `host` on the blocking pool, then runs
Expand Down
10 changes: 7 additions & 3 deletions crates/workshop/agents/src/tee-tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ fn record(kind: RecordKind, event: &Event) -> Record {

/// An inner recorder that notes, at each append, how many entries the
/// conversation's transcript already held, and refuses appends on demand.
/// It leaves `append_event` at its default, so the record of an event
/// reaches its `append` as every other record does.
struct Watching {
inner: MemoryRecorder,
conversation: Conversation,
Expand Down Expand Up @@ -96,7 +98,8 @@ async fn the_tee_adds_an_event_to_the_transcript_after_the_inner_recorder_accept
let (conversation, inner, tee) = watched(false);
let mut live = conversation.subscribe_events();
let run = tee.begin_run(meta()).await.unwrap();
tee.append(run, record(RecordKind::Event, &section_started()))
let event = section_started();
tee.append_event(run, record(RecordKind::Event, &event), &event)
.await
.unwrap();
assert_eq!(
Expand All @@ -123,8 +126,9 @@ async fn the_tee_returns_the_inner_recorders_refusal_and_keeps_the_event_out() {
let (conversation, _inner, tee) = watched(true);
let mut live = conversation.subscribe_events();
let run = tee.begin_run(meta()).await.unwrap();
let event = section_started();
let refusal = tee
.append(run, record(RecordKind::Event, &section_started()))
.append_event(run, record(RecordKind::Event, &event), &event)
.await
.expect_err("the inner recorder's refusal is the tee's");
assert_eq!(
Expand Down Expand Up @@ -179,7 +183,7 @@ async fn recorded_turn_failures_report_their_kind_and_section() {
provenance: provenance(),
};
for event in [&model, &tool] {
tee.append(run, record(RecordKind::Event, event))
tee.append_event(run, record(RecordKind::Event, event), event)
.await
.unwrap();
}
Expand Down
36 changes: 17 additions & 19 deletions crates/workshop/agents/src/tee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@
//! to the inner recorder, and what the inner recorder accepted also
//! reaches the conversation.
//!
//! The tee notes the run the inner recorder begins and hands each event
//! record the inner recorder accepted to the conversation, so the record,
//! the live broadcast, and the transcript agree event for event. A refused write
//! The tee notes the run the inner recorder begins. The Harness hands it
//! each event with the event's record. The tee passes both on to the
//! inner recorder, and it hands the event to the conversation once the
//! inner recorder has accepted the record, so the record, the live
//! broadcast, and the transcript agree event for event. A refused write
//! is returned as the inner recorder's own, and its event reaches no one.

use std::sync::Arc;

use runvil::event::Event;
use runvil::harness::{Record, RecordKind, RunId, RunMeta, RunRecorder};
use runvil::harness::{Record, RunId, RunMeta, RunRecorder};
use runvil::{BoxFuture, Error};

use crate::conversation::Conversation;
Expand Down Expand Up @@ -41,22 +43,18 @@ impl RunRecorder for ConversationRecorder {
}

fn append(&self, run: RunId, record: Record) -> BoxFuture<'_, Result<(), Error>> {
self.inner.append(run, record)
}

fn append_event<'a>(
&'a self,
run: RunId,
record: Record,
event: &'a Event,
) -> BoxFuture<'a, Result<(), Error>> {
Box::pin(async move {
let event = (record.kind == RecordKind::Event).then(|| record.payload.clone());
self.inner.append(run, record).await?;
if let Some(payload) = event {
// The run serialized this event for the record a moment
// ago, so it reads back; a payload that does not is
// logged and left out of the transcript.
match serde_json::from_value::<Event>(payload) {
Ok(event) => self.conversation.observe(&event),
Err(error) => tracing::error!(
conversation = %self.conversation.id(),
%error,
"a recorded event did not read back; the transcript skips it"
),
}
}
self.inner.append_event(run, record, event).await?;
self.conversation.observe(event);
Ok(())
})
}
Expand Down
8 changes: 2 additions & 6 deletions crates/workshop/agents/tests/it/support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,7 @@ pub(crate) fn run_for(
source: String,
) -> (Arc<Host>, RunSetup) {
let host = Host::builder(FindTextPrompt::new(AGENT, source)).build();
let setup = RunSetup::new(
conversation.recorder(recorder),
Arc::new(OfflineBroker),
Arc::new(TokioTimer),
)
.has_user(true);
let setup =
RunSetup::new(conversation.recorder(recorder), OfflineBroker, TokioTimer).has_user(true);
(host, setup)
}
11 changes: 3 additions & 8 deletions crates/workshop/server/src/agents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,14 +466,9 @@ impl AgentSessions {
/// the stock tokio timer, its filesystem, and a user, since every
/// conversation has an operator.
fn setup_for(&self, conversation: &Conversation) -> RunSetup {
let recorder = conversation.recorder(Arc::new(
self.inner.recorder.for_agent(conversation.agent()),
));
let broker = Arc::new(RunBroker::new(
self.inner.broker.clone(),
conversation.clone(),
));
RunSetup::new(recorder, broker, Arc::new(TokioTimer))
let recorder = conversation.recorder(self.inner.recorder.for_agent(conversation.agent()));
let broker = RunBroker::new(self.inner.broker.clone(), conversation.clone());
RunSetup::new(recorder, broker, TokioTimer)
.vfs(language_guide::run_vfs())
.has_user(true)
}
Expand Down
8 changes: 1 addition & 7 deletions crates/workshop/server/src/agents/bindings-tests.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//! Host binding tests: a run's setup takes the menu's selection.

use std::sync::Arc;

use harness_gateway_client::TokioTimer;
use runvil::harness::{MemoryRecorder, OfflineBroker};
use workshop_menu::{CatalogBus, MenuBus};
Expand All @@ -10,11 +8,7 @@ use super::*;

/// A setup with nothing selected.
fn empty_setup() -> RunSetup {
RunSetup::new(
Arc::new(MemoryRecorder::new()),
Arc::new(OfflineBroker),
Arc::new(TokioTimer),
)
RunSetup::new(MemoryRecorder::new(), OfflineBroker, TokioTimer)
}

#[test]
Expand Down
4 changes: 2 additions & 2 deletions crates/workshop/server/src/agents/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ async fn run_agent_on(
let mut errors = conversation.subscribe_errors();
let setup = RunSetup::new(
conversation.recorder(recorder.clone()),
Arc::new(OfflineBroker),
Arc::new(TokioTimer),
OfflineBroker,
TokioTimer,
)
.vfs(vfs)
.has_user(true);
Expand Down
Loading