Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
8d918f5
feat(runtime): describe a Session from its own scope
eric8810 Nov 28, 2026
2f74b18
refactor: retarget the Session and timeline identity injections (bloc…
eric8810 Nov 28, 2026
ee6681d
refactor: read identities and session ids from the new owners
eric8810 Nov 28, 2026
1a75aa1
refactor: read the timeline context on demand in three branch parts
eric8810 Nov 28, 2026
4ba37c4
refactor: look the timeline context up on demand across the branch parts
eric8810 Nov 28, 2026
145ce52
refactor: carry the branch ids on BranchLifecycle (partial)
eric8810 Nov 28, 2026
71ef06b
refactor: read the branch ids from BranchLifecycle in the branch parts
eric8810 Nov 28, 2026
09d8cea
refactor: remove the duplicate branch-lifecycle fields (still red)
eric8810 Nov 28, 2026
29697d0
refactor: name the hooks session key after what it carries
eric8810 Nov 28, 2026
7910905
refactor: read the broadcast ids from the branch lifecycle
eric8810 Nov 28, 2026
6b9e66f
refactor: keep one branch lifecycle key in the shell session plugin
eric8810 Nov 28, 2026
b78a546
refactor: read branch ids from BranchLifecycle and drop the timelineI…
eric8810 Nov 28, 2026
d320325
refactor: point the config readers at the Session scope (intermediate)
eric8810 Nov 28, 2026
ac1a058
refactor: read the questions config and the face test through describe()
eric8810 Nov 28, 2026
0b772ee
refactor: take the session configuration from the scope in the aimux …
eric8810 Nov 28, 2026
961c9bb
refactor: remove the sessionIdentity, sessionConfig, agentConfig and …
eric8810 Nov 28, 2026
2c5c74a
refactor: read the session configuration from the scope in five more …
eric8810 Nov 28, 2026
e09be66
refactor: finish the session read migration and drop its three faces
eric8810 Nov 28, 2026
8e5a19a
style: format after the rebase conflict resolution
eric8810 Nov 28, 2026
eba40a6
test(xtask): keep the retired-name guard honest about what it covers
eric8810 Nov 28, 2026
d2031ff
fix(runtime): keep the description readable while the Session closes
eric8810 Nov 28, 2026
051eaf9
fix(aimux): look the model defaults up for the Session's own model
eric8810 Nov 28, 2026
e987cb2
test(aimux): pin the Session model's defaults and an unknown model's …
eric8810 Nov 28, 2026
b4cded5
refactor(sdk): move the fixtures and the scheduler test to the new reads
eric8810 Nov 28, 2026
47eaeea
fix(xtask): refuse a retired name that returns as an instance registr…
eric8810 Nov 28, 2026
1c7d9ca
test: migrate the remaining TimelineIdentity fixtures to BranchLifecycle
eric8810 Nov 29, 2026
dc1be50
docs: retire the identity and configuration faces from the contract a…
eric8810 Nov 29, 2026
4c2e727
test: drop the last retired-service injections from the fixtures
eric8810 Nov 29, 2026
257a469
fix: read describe() in the observer fixture and tidy the pages the r…
eric8810 Nov 29, 2026
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
32 changes: 16 additions & 16 deletions crates/dim-agent-aimux/src/plugin.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{AimuxModels, driver::AimuxDriver, identity::ModelIdentity};
use dim_agent_capabilities::host::*;
use dim_agent_runtime::{Names, SessionConfig, SessionIdentity};
use dim_agent_runtime::{Names, SessionConfig, SessionScope};
use dim_agent_types::{Message, SystemPrompt, ToolDefinition};
use rutis::host::{BoxFuture, CtxHost, DynPlugin, Effect, ErrorKind, Key, TypeKey};
use rutis::{Ctx, Plugin};
Expand Down Expand Up @@ -292,16 +292,14 @@ impl ResolveModalityConnection for ConfiguredConnection {
pub struct ConfiguredModelPlugin {
prepare: Key<PrepareModelHost>,
models: Key<AimuxModels>,
config: Key<SessionConfig>,
identity: Key<SessionIdentity>,
scope: Key<SessionScope>,
}
impl ConfiguredModelPlugin {
pub fn new(names: &Names<'_>) -> rutis::Result<Self> {
Ok(Self {
prepare: names.key()?,
models: names.key()?,
config: names.key()?,
identity: names.key()?,
scope: names.key()?,
})
}
}
Expand All @@ -310,19 +308,21 @@ impl DynPlugin for ConfiguredModelPlugin {
"ConfiguredModel"
}
fn injects(&self) -> Vec<TypeKey> {
vec![
self.models.erase(),
self.config.erase(),
self.identity.erase(),
]
vec![self.models.erase(), self.scope.erase()]
}
fn apply<'a>(&'a self, ctx: &'a Ctx) -> BoxFuture<'a, rutis::Result<Effect>> {
Box::pin(async move {
let models = ctx.require_at(&self.models)?;
let config = ctx.require_at(&self.config)?;
let identity = ctx.require_at(&self.identity)?;
let scope = ctx.require_at(&self.scope)?;
let description = scope.describe().map_err(|error| {
rutis::Error::msg(format!("Session description unavailable: {error}"))
})?;
// The defaults are the selected Session model's, not the owning
// Agent's: the request is prepared for the Session's model.
let model = description.config.model.clone();
let config = Arc::new(description.config);
let defaults = models
.get(&config.model.provider_id, &config.model.model_id)
.get(&model.provider_id, &model.model_id)
.map_err(|error| {
rutis::Error::from(ErrorKind::Validation {
issues: vec![error.to_string()],
Expand All @@ -334,7 +334,7 @@ impl DynPlugin for ConfiguredModelPlugin {
self.prepare.clone(),
Arc::new(PrepareModelHost(Arc::new(Prepare {
config,
identity,
identity: scope.clone(),
defaults,
}))),
)?;
Expand All @@ -349,7 +349,7 @@ pub(crate) const REQUEST_ID_EXTENSION: &str = "requestId";

struct Prepare {
config: Arc<SessionConfig>,
identity: Arc<SessionIdentity>,
identity: Arc<SessionScope>,
defaults: dim_agent_types::ModelConfig,
}
impl PrepareModel for Prepare {
Expand All @@ -371,7 +371,7 @@ impl PrepareModel for Prepare {
.then(|| SystemPrompt::Text(self.config.system_prompt.clone()));
settings.tools = Some(available_tools.to_vec());
let mut metadata = self.config.model.metadata.clone().unwrap_or_default();
metadata.session_id = Some(self.identity.session_id.clone());
metadata.session_id = Some(self.identity.session_id().clone());
metadata.turn_id = Some(turn_id.into());
metadata
.extensions
Expand Down
86 changes: 86 additions & 0 deletions crates/dim-agent-aimux/tests/model_flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1838,3 +1838,89 @@ async fn a_wait_for_response_headers_past_the_idle_allowance_fails_as_a_network_

#[path = "model_flow/native.rs"]
mod native;

/// A catalog of two models whose catalog defaults differ, so a request shows
/// which one supplied them.
fn two_model_configuration(url: &str) -> ModelConfigFile {
serde_json::from_value(json!({
"defaultModel": {"providerId": "local", "modelId": "agent-model"},
"providers": [{
"id": "local",
"kind": "openai-compatible",
"baseUrl": url,
"models": [
{"id": "agent-model", "contextWindow": 128000, "maxOutputTokens": 4096, "config": {"maxTokens": 1111}},
{"id": "session-model", "contextWindow": 64000, "maxOutputTokens": 2048, "config": {"maxTokens": 2222}}
]
}]
}))
.unwrap()
}

/// The prepared request takes its defaults from the Session's own model, not
/// from the owning Agent's.
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn the_session_models_defaults_prepare_its_request() {
let server = TestServer::start().await;
let models = Arc::new(AimuxModels::from_config(two_model_configuration(&server.url)).unwrap());
let host = model_agent(models, None).await;
let agent = host.agent();
let mut session = session_config();
session.model.model_id = "session-model".into();
session.model.config = None;
let session = agent
.create_session(session, Default::default())
.await
.unwrap();
session
.submit("text".into(), InputMode::Queue, "main")
.await
.unwrap();
session.idle("main").await.unwrap();
let events = chain_events(&session, "main", ..).await.unwrap();
let call = events
.iter()
.find_map(|event| match &event.kind {
EventKind::ModelCall(call) => Some(call),
_ => None,
})
.expect("the turn calls the model");
assert_eq!(
call.request.config.as_ref().unwrap().max_tokens,
Some(2048.0),
"the Session model's catalogue defaults (2048), not the Agent model's (4096)"
);
assert_eq!(
call.request.model_id, "session-model",
"the request is prepared for the Session's model"
);
session.close().await.unwrap();
host.close().await.unwrap();
server.close().await;
}

/// A model the catalog does not know is refused instead of falling back to the
/// Agent's model.
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn an_unknown_session_model_is_refused() {
let server = TestServer::start().await;
let models = Arc::new(AimuxModels::from_config(two_model_configuration(&server.url)).unwrap());
let host = model_agent(models, None).await;
let agent = host.agent();
let mut session = session_config();
session.model.model_id = "missing-model".into();
let error = match agent.create_session(session, Default::default()).await {
Ok(session) => {
session.close().await.unwrap();
panic!("an unknown model must be refused");
}
Err(error) => error,
};
let message = error.to_string();
assert!(
message.contains("missing-model"),
"the refusal names the model: {message}"
);
host.close().await.unwrap();
server.close().await;
}
6 changes: 3 additions & 3 deletions crates/dim-agent-attachments/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use dim_agent_capabilities::{
host::{SessionFileError, SessionFileErrorCode, SessionFiles},
methods::{self, Interruption, MethodCall, MethodDecl, RpcError, SessionMethods},
};
use dim_agent_runtime::{AgentBuilder, Names, SessionIdentity};
use dim_agent_runtime::{AgentBuilder, Names, SessionScope};
use rutis::Ctx;
use rutis::host::{BoxFuture, CtxHost, DynPlugin, Effect, Key, TypeKey};
use std::{path::PathBuf, sync::Arc};
Expand Down Expand Up @@ -114,7 +114,7 @@ fn prepare_image(path: String) -> Result<(tempfile::NamedTempFile, &'static str)
}

pub struct AttachmentsPlugin {
identity: Key<SessionIdentity>,
identity: Key<SessionScope>,
files: Key<SessionFiles>,
methods: Key<SessionMethods>,
}
Expand Down Expand Up @@ -143,7 +143,7 @@ impl DynPlugin for AttachmentsPlugin {
let identity = ctx.require_at(&self.identity)?;
let files = ctx.require_at(&self.files)?;
let methods = ctx.require_at(&self.methods)?;
let session_id = identity.session_id.clone();
let session_id = identity.session_id().clone();
methods.register(
ctx,
NAMESPACE,
Expand Down
13 changes: 10 additions & 3 deletions crates/dim-agent-capabilities/src/adapters.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Deterministic in-process hosts for prototype and transport tests.
use crate::{host::*, tool_registry::definition};
use dim_agent_runtime::{Names, SessionConfig};
use dim_agent_runtime::{Names, SessionConfig, SessionScope};
use dim_agent_types::*;
use rutis::Ctx;
use rutis::host::{BoxFuture, CtxHost, DynPlugin, Effect, Key, TypeKey};
Expand Down Expand Up @@ -250,7 +250,7 @@ impl PrepareModel for DefaultPrepareModel {
}
pub struct DefaultPrepareModelPlugin {
host: Key<PrepareModelHost>,
config: Key<SessionConfig>,
config: Key<SessionScope>,
}
impl DefaultPrepareModelPlugin {
pub fn new(names: &Names<'_>) -> rutis::Result<Self> {
Expand All @@ -269,7 +269,14 @@ impl DynPlugin for DefaultPrepareModelPlugin {
}
fn apply<'a>(&'a self, ctx: &'a Ctx) -> BoxFuture<'a, rutis::Result<Effect>> {
Box::pin(async move {
let config = ctx.require_at(&self.config)?;
let config = Arc::new(
ctx.require_at(&self.config)?
.describe()
.map_err(|error| {
rutis::Error::msg(format!("Session description unavailable: {error}"))
})?
.config,
);
ctx.provide_at(
self.host.clone(),
Arc::new(PrepareModelHost(Arc::new(DefaultPrepareModel { config }))),
Expand Down
18 changes: 9 additions & 9 deletions crates/dim-agent-capabilities/src/agent_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ use crate::{
tool_binding::ToolBinding,
};
use dim_agent_runtime::{
AgentError, CAPABILITY_RELOADING, Dispatcher, LoopPhase, LoopSnapshot, LoopState, Names,
QueryComparison, QueryFilter, QueryOperand, QueryOutput, QueryPage, QueryPick, QuerySelect,
QuerySpec, QueryValue, Result, StateCell, Timeline, TimelineIdentity, TimelineQuery,
AgentError, BranchLifecycle, CAPABILITY_RELOADING, Dispatcher, LoopPhase, LoopSnapshot,
LoopState, Names, QueryComparison, QueryFilter, QueryOperand, QueryOutput, QueryPage,
QueryPick, QuerySelect, QuerySpec, QueryValue, Result, StateCell, Timeline, TimelineQuery,
TimelineQueryScope,
};
use dim_agent_types::*;
Expand Down Expand Up @@ -1806,7 +1806,7 @@ pub struct LoopPlugin {
context: Key<ContextModelHost>,
strategy: Key<CompactionStrategyHost>,
guide: Key<crate::prompt_guide::GuideEntries>,
identity: Key<TimelineIdentity>,
lifecycle: Key<BranchLifecycle>,
}
impl LoopPlugin {
pub fn new(names: &Names<'_>) -> rutis::Result<Self> {
Expand All @@ -1823,7 +1823,7 @@ impl LoopPlugin {
context: names.key()?,
strategy: names.key()?,
guide: names.key()?,
identity: names.key()?,
lifecycle: names.key()?,
})
}
}
Expand All @@ -1833,6 +1833,7 @@ impl DynPlugin for LoopPlugin {
}
fn injects(&self) -> Vec<TypeKey> {
vec![
self.lifecycle.erase(),
self.timeline.erase(),
self.dispatcher.erase(),
self.prepare.erase(),
Expand All @@ -1842,7 +1843,6 @@ impl DynPlugin for LoopPlugin {
self.context.erase(),
self.strategy.erase(),
self.guide.erase(),
self.identity.erase(),
]
}
fn apply<'a>(&'a self, ctx: &'a Ctx) -> BoxFuture<'a, rutis::Result<Effect>> {
Expand All @@ -1855,7 +1855,7 @@ impl DynPlugin for LoopPlugin {
let context = ctx.require_at(&self.context)?;
let strategy = ctx.require_at(&self.strategy)?;
let guide = ctx.require_at(&self.guide)?;
let identity = ctx.require_at(&self.identity)?;
let lifecycle = ctx.require_at(&self.lifecycle)?;
let policy = ContextPolicy::bind(&timeline, &context, &strategy, &history)
.map_err(|error| rutis::Error::from(ErrorKind::PluginFailed(error.into())))?;
let service = Arc::new(AgentLoop {
Expand All @@ -1871,8 +1871,8 @@ impl DynPlugin for LoopPlugin {
history,
preparation: ctx.require_at(&self.preparation)?,
guide,
branch: identity.branch_id.clone(),
session_id: identity.session_id.clone(),
branch: lifecycle.branch_id().clone(),
session_id: lifecycle.session_id().clone(),
policy,
tasks: TaskTracker::new(),
lifecycle: ctx.cancellation_token(),
Expand Down
Loading
Loading