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
21 changes: 21 additions & 0 deletions plugins/agent/facts/src/cells.rs
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,27 @@ impl CellChild {
result.settlement == ToolSettlement::Returned && !result.is_error
})
}
/// The tool gave the cell a result or an error.
pub fn returned(&self) -> bool {
self.rejected.is_none()
&& (self
.local_result
.as_ref()
.or(self.provider_result.as_ref())
.is_some_and(|result| {
matches!(
result.settlement,
ToolSettlement::Returned | ToolSettlement::Failed
)
})
|| matches!(
self.reply.as_ref().map(|reply| &reply.receipt),
Some(Receipt::Recorded {
outcome: OperationOutcome::Returned { .. },
..
})
))
}
pub fn physical_cleanup_confirmed(&self) -> bool {
self.rejected.is_some()
|| self
Expand Down
46 changes: 45 additions & 1 deletion plugins/agent/native/src/owner/discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,18 @@ fn investigation_prompt(
prompt
}

/// Calls that do not investigate, so they are not evidence for a result.
const NOT_EVIDENCE: &[&str] = &[
COMPLETE,
super::compaction::TOOL,
"AskUserQuestion",
maka_tools::availability::SEARCH,
"exec",
"wait",
"todo_read",
"todo_write",
];

fn report_message(
language: Language,
title: &str,
Expand Down Expand Up @@ -287,7 +299,7 @@ impl scheduler::Scheduler {
ToolRegistration {
definition: ToolDefinition {
provider: None, name: COMPLETE.into(),
description: "Finish this investigation. Both no_report and report accept optional notes, an array of {text, references} objects with concise new observations and source references. Use report for findings worth notifying the user about. This stores the result and ends the Turn.".into(),
description: "Finish this investigation. Both no_report and report accept optional notes, an array of {text, references} objects with concise new observations and source references. Use report for findings worth notifying the user about. This stores the result and ends the Turn. It is not a first step or a placeholder: when you have other tools, call it alone after they have returned what you need.".into(),
input_schema: serde_json::to_value(schemars::schema_for!(ToolRequest<Report>)).expect("discovery schema"),
output_schema: None, freeform: None,
},
Expand Down Expand Up @@ -344,6 +356,38 @@ impl scheduler::Scheduler {
}

impl Owner {
/// A worker that can investigate must get a tool result before it submits one.
pub(super) async fn require_discovery_evidence(
&self,
catalog: &maka_tools::ToolCatalog,
context: &ToolCallContext,
) -> Result<(), ToolRejection> {
if catalog
.definitions()
.all(|tool| NOT_EVIDENCE.contains(&tool.name.as_str()))
{
return Ok(());
}
let attempt = match &context.call.origin {
maka_agent_facts::tool_call::ToolOrigin::Provider { link } => Some(link.attempt),
_ => None,
};
let returned = self
.durable
.run_tool_returned(context.execution.run_id, attempt, NOT_EVIDENCE)
.await
.map_err(|error| ToolRejection::PreparationFailed {
message: error.to_string(),
})?;
if returned {
return Ok(());
}
Err(ToolRejection::PolicyDenied {
message: format!(
"{COMPLETE} submits the result and ends the investigation, but no investigation tool has returned anything to you in this run yet. It is not a first step or a placeholder. Investigate with your other tools first (inside exec when they are not offered as separate functions), then call {COMPLETE} alone in a later step."
),
})
}
pub(super) async fn restore_discovery(&self) -> Result<(), String> {
let (revision, job) = self.scheduler.investigation().await?;
let Some(mut job) = job else {
Expand Down
3 changes: 3 additions & 0 deletions plugins/agent/native/src/owner/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ impl PreparedTool {
cancellation: CancellationToken,
semantics: ToolSemantics,
) -> Result<Self, ToolRejection> {
if name == super::discovery::COMPLETE {
owner.require_discovery_evidence(catalog, &context).await?;
}
if name == super::compaction::TOOL
&& let Some(target) = input.get("resumeModel")
{
Expand Down
Loading