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
12 changes: 7 additions & 5 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ members = [
resolver = "2"

[workspace.package]
version = "0.11.0"
version = "0.12.0"
2 changes: 1 addition & 1 deletion clients/python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "lightspeed-ai"
version = "0.11.0"
version = "0.12.0"
description = "Async Python SDK for the Lightspeed HTTP API"
readme = "README.md"
requires-python = ">=3.12"
Expand Down
2 changes: 1 addition & 1 deletion clients/python/uv.lock

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

101 changes: 70 additions & 31 deletions crates/api-projection/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1288,12 +1288,16 @@ impl<'a> CoreAgentProjector<'a> {
try_join_all(calls.iter().map(|call| async move {
let arguments = self.read_blob_text(&call.arguments_ref).await?;
Ok(ToolCallEventView {
tool_id: call.tool_id.as_ref().map(|id| id.as_str().to_owned()),
tool_id: call.tool_id().map(|id| id.as_str().to_owned()),
call_id: call.call_id.as_str().to_owned(),
tool_name: call.tool_name.as_str().to_owned(),
arguments_ref: call.arguments_ref.as_str().to_owned(),
arguments: Some(truncate_utf8(&arguments, MAX_INLINE_TEXT_BYTES)),
display: tool_call_display(call.tool_name.as_str(), &arguments),
display: tool_call_display(
call.target.as_ref(),
call.tool_name.as_str(),
&arguments,
),
})
}))
.await
Expand Down Expand Up @@ -1328,7 +1332,7 @@ impl<'a> CoreAgentProjector<'a> {
let result = result_by_call.get(call.call_id.as_str());
let arguments = self.read_blob_text(&call.arguments_ref).await?;
Ok(ToolCallView {
tool_id: call.tool_id.as_ref().map(|id| id.as_str().to_owned()),
tool_id: call.tool_id().map(|id| id.as_str().to_owned()),
call_id: call.call_id.as_str().to_owned(),
tool_name: call.tool_name.as_str().to_owned(),
arguments_ref: call.arguments_ref.as_str().to_owned(),
Expand All @@ -1344,7 +1348,7 @@ impl<'a> CoreAgentProjector<'a> {
// A call that names no tool never starts. Any other is
// only requested until its start commits.
status: result.map(|result| result.status).unwrap_or(
if call.tool_id.is_some() {
if call.target.is_some() {
ToolItemStatus::Requested
} else {
ToolItemStatus::Unavailable
Expand All @@ -1358,7 +1362,11 @@ impl<'a> CoreAgentProjector<'a> {
.get(call.call_id.as_str())
.cloned()
.unwrap_or_default(),
display: tool_call_display(call.tool_name.as_str(), &arguments),
display: tool_call_display(
call.target.as_ref(),
call.tool_name.as_str(),
&arguments,
),
started_at_ms: None,
finished_at_ms: None,
duration_ms: None,
Expand Down Expand Up @@ -2995,8 +3003,25 @@ fn json_field_text(value: &Value, field: &str) -> Option<String> {
(!text.is_empty()).then_some(text)
}

fn tool_call_display(tool_name: &str, arguments: &str) -> Option<ToolCallDisplayView> {
fn tool_call_display(
target: Option<&harness::ResolvedToolTarget>,
tool_name: &str,
arguments: &str,
) -> Option<ToolCallDisplayView> {
let json = serde_json::from_str::<Value>(arguments).ok();
if let Some(harness::ResolvedToolTarget::Mcp {
server_label,
remote_name,
..
}) = target
{
return Some(ToolCallDisplayView {
group: ToolCallDisplayGroup::Mcp,
verb: server_label.clone(),
target: Some(remote_name.clone()),
detail: json.as_ref().and_then(first_scalar_text),
});
}
let normalized = tool_name.to_ascii_lowercase();
let view = match normalized.as_str() {
"code_execute" => ToolCallDisplayView {
Expand Down Expand Up @@ -3345,19 +3370,6 @@ fn tool_call_display(tool_name: &str, arguments: &str) -> Option<ToolCallDisplay
.map(|ms| format!("{ms} ms")),
detail: None,
},
_ if tool_name
.strip_prefix("mcp_")
.and_then(|name| name.split_once("__"))
.is_some_and(|(server, tool)| !server.is_empty() && !tool.is_empty()) =>
{
let (server, tool) = tool_name.strip_prefix("mcp_")?.split_once("__")?;
ToolCallDisplayView {
group: ToolCallDisplayGroup::Mcp,
verb: server.to_owned(),
target: Some(tool.to_owned()),
detail: json.as_ref().and_then(first_scalar_text),
}
}
_ => ToolCallDisplayView {
group: ToolCallDisplayGroup::Other,
verb: tool_name.to_owned(),
Expand Down Expand Up @@ -3678,20 +3690,20 @@ mod tests {

#[test]
fn code_display_summarizes_source_without_exposing_it_in_the_row() {
let display = tool_call_display("code_execute", r#"{"code":"const result = await tools.vfs_read_file({path:'/notes'});\ntext(result);\n"}"#).unwrap();
let display = tool_call_display(None, "code_execute", r#"{"code":"const result = await tools.vfs_read_file({path:'/notes'});\ntext(result);\n"}"#).unwrap();
assert_eq!(display.group, ToolCallDisplayGroup::Code);
assert_eq!(display.verb, "Run code");
assert_eq!(display.target.as_deref(), Some("JavaScript"));
assert_eq!(display.detail.as_deref(), Some("2 lines"));
assert_eq!(
tool_call_display("code_execute", r#"{"code":"return 1"}"#)
tool_call_display(None, "code_execute", r#"{"code":"return 1"}"#)
.unwrap()
.detail
.as_deref(),
Some("1 line")
);
for arguments in ["{", "{}", r#"{"code":" "}"#] {
let display = tool_call_display("code_execute", arguments).unwrap();
let display = tool_call_display(None, "code_execute", arguments).unwrap();
assert_eq!(display.group, ToolCallDisplayGroup::Code);
assert_eq!(display.detail, None);
}
Expand Down Expand Up @@ -3751,7 +3763,7 @@ mod tests {
),
] {
for name in names {
let display = tool_call_display(name, args).unwrap();
let display = tool_call_display(None, name, args).unwrap();
assert_eq!(display.group, group, "{name}");
assert_eq!(display.verb, verb, "{name}");
assert_eq!(display.target.as_deref(), Some(target), "{name}");
Expand Down Expand Up @@ -3847,7 +3859,7 @@ mod tests {
"process1",
),
] {
let display = tool_call_display(name, args).unwrap();
let display = tool_call_display(None, name, args).unwrap();
assert_eq!(display.group, group, "{name}");
assert_eq!(display.verb, verb, "{name}");
assert_eq!(display.target.as_deref(), Some(target), "{name}");
Expand All @@ -3859,13 +3871,32 @@ mod tests {

#[test]
fn injected_mcp_display_preserves_names_and_unknown_tools_stay_generic() {
let display = tool_call_display("mcp_docs__Search", r#"{"query":"QuickJS"}"#).unwrap();
let binding = harness::ResolvedToolTarget::Mcp {
server_tool_id: harness::ToolId::new("mcp_docs__internal"),
server_label: "docs__internal".into(),
remote_name: "search_by_document_metadata".into(),
};
let display = tool_call_display(
Some(&binding),
"mcp_docs__search_hash_metadata",
r#"{"query":"QuickJS"}"#,
)
.unwrap();
assert_eq!(display.group, ToolCallDisplayGroup::Mcp);
assert_eq!(display.verb, "docs");
assert_eq!(display.target.as_deref(), Some("Search"));
assert_eq!(display.verb, "docs__internal");
assert_eq!(
display.target.as_deref(),
Some("search_by_document_metadata")
);
assert_eq!(display.detail.as_deref(), Some("QuickJS"));
for name in ["custom_tool", "mcp_unknown", "mcp___", "mcp_docs__"] {
let display = tool_call_display(name, "{}").unwrap();
for name in [
"mcp_docs__Search",
"custom_tool",
"mcp_unknown",
"mcp___",
"mcp_docs__",
] {
let display = tool_call_display(None, name, "{}").unwrap();
assert_eq!(display.group, ToolCallDisplayGroup::Other);
assert_eq!(display.verb, name);
}
Expand All @@ -3874,6 +3905,7 @@ mod tests {
#[test]
fn runtime_mcp_search_call_displays_the_resolved_server_and_tool() {
let display = tool_call_display(
None,
"mcp_call",
r#"{"server":"configurator","tool":"lightspeed_models_list","arguments":{}}"#,
)
Expand All @@ -3884,6 +3916,7 @@ mod tests {
assert_eq!(display.detail, None);

let display = tool_call_display(
None,
"mcp_call",
r#"{"server":"stripe","tool":"retrieve_subscription","arguments":{"id":"sub_1R0aB3"}}"#,
)
Expand Down Expand Up @@ -3912,6 +3945,7 @@ mod tests {
#[test]
fn subagent_calls_display_the_profile_and_the_brief() {
let display = tool_call_display(
None,
"agent_run",
r#"{"agent":"reviewer","input":"Review the diff on skills2.\n\nFocus on tests."}"#,
)
Expand All @@ -3925,6 +3959,7 @@ mod tests {
);

let display = tool_call_display(
None,
"agent_spawn",
r#"{"agent":"researcher","input":"Find prior art","label":"Prior art"}"#,
)
Expand All @@ -3933,6 +3968,7 @@ mod tests {
assert_eq!(display.detail.as_deref(), Some("Prior art"));

let display = tool_call_display(
None,
"await",
r#"{"promises":["promise_3","promise_4"],"mode":"any"}"#,
)
Expand All @@ -3946,6 +3982,7 @@ mod tests {
#[test]
fn bot_emit_distinguishes_self_from_addressed_peers() {
let display = tool_call_display(
None,
"bot_emit",
r#"{"kind":"bug.confirmed","summary":"Duplicates on page boundary","to":"escalations","reply":true}"#,
)
Expand All @@ -3959,6 +3996,7 @@ mod tests {
);

let display = tool_call_display(
None,
"bot_emit",
r#"{"kind":"research.followup","summary":"Nightly","sessionKey":"nightly"}"#,
)
Expand All @@ -3982,6 +4020,7 @@ mod tests {
#[test]
fn runtime_mcp_detail_display_names_the_requested_tools() {
let display = tool_call_display(
None,
"mcp_find_tools",
r#"{"server":"configurator","names":["models_list","sessions_read"]}"#,
)
Expand Down Expand Up @@ -4077,7 +4116,7 @@ mod tests {
let batch_id = harness::ToolBatchId::new(1);
let call = |id: &str, tool_id: Option<&str>| harness::ObservedToolCall {
call_id: harness::ToolCallId::new(id),
tool_id: tool_id.map(harness::ToolId::new),
target: tool_id.map(harness::ToolId::new).map(Into::into),
tool_name: harness::ToolName::new("read_file"),
provider_kind: None,
arguments_ref: arguments_ref.clone(),
Expand Down Expand Up @@ -5775,7 +5814,7 @@ mod tests {
toolset_revision: 0,
calls: vec![harness::ObservedToolCall {
call_id: call_id.clone(),
tool_id: None,
target: None,
tool_name: harness::ToolName::new("mcp_echo__hello"),
provider_kind: None,
arguments_ref: arguments_ref.clone(),
Expand Down
18 changes: 12 additions & 6 deletions crates/harness/src/core/components/code_tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ pub(crate) fn interrupt_code_tools_for_run(state: &mut CoreAgentState, run_id: c

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct CodeToolBinding {
pub tool_id: ToolId,
#[serde(alias = "tool_id")]
pub target: crate::ResolvedToolTarget,
pub tool_name: ToolName,
}

Expand Down Expand Up @@ -334,13 +335,13 @@ fn validate_scope(state: &CoreAgentState, scope: &CodeToolScopeSpec) -> Result<(
.ok_or_else(|| invalid("code tool parent binding is missing"))?;
for (binding_id, binding) in &scope.bindings {
validate_id("binding_id", binding_id)?;
let tool_id = &binding.tool_id;
let tool_id = binding.target.tool_id();
let tool = state
.tooling
.tools
.get(tool_id)
.ok_or_else(|| invalid(format!("code tool {tool_id} is not granted")))?;
if !tool.invokes_client_effect() || tool_id == &parent_tool.definition.tool.id {
if !tool.admits_call(&binding.target) || tool_id == &parent_tool.definition.tool.id {
return Err(invalid(format!(
"tool {tool_id} is not available for code tool execution"
)));
Expand Down Expand Up @@ -375,7 +376,7 @@ fn validate_recorded_call<'a>(
.bindings
.get(&call.binding_id)
.is_some_and(|binding| {
binding.tool_id == call.tool_id && binding.tool_name == call.tool_name
binding.target.tool_id() == &call.tool_id && binding.tool_name == call.tool_name
})
{
return Err(invalid("code tool is outside the execution grant"));
Expand Down Expand Up @@ -826,6 +827,11 @@ pub fn code_tool_request(
"code tool request session does not match its parent",
));
}
let binding = scope
.spec
.bindings
.get(&call.spec.binding_id)
.ok_or_else(|| invalid("code tool binding is absent from its scope"))?;
let mut request = crate::core::drive::tool_invocation_request(
state,
session_id,
Expand All @@ -835,8 +841,8 @@ pub fn code_tool_request(
call.promise_id_base,
std::slice::from_ref(&crate::ObservedToolCall {
call_id: call.call_id.clone(),
tool_id: Some(call.spec.tool_id.clone()),
tool_name: call.spec.tool_name.clone(),
target: Some(binding.target.clone()),
tool_name: binding.tool_name.clone(),
provider_kind: None,
arguments_ref: call.spec.arguments_ref.clone(),
native_call_ref: None,
Expand Down
Loading