provenance: pass directly through thought::dispatch, remove globals
Provenance now flows as a function parameter through the entire tool dispatch chain: thought::dispatch → memory::dispatch → store methods. Removed task_local (TASK_AGENT), thread_local (TASK_PHASE), and env var (POC_PROVENANCE) from the tool dispatch path. The env var remains only as a fallback for non-tool paths (CLI commands, digest). Phase names are passed from knowledge.rs → llm.rs → api.rs, and api.rs updates the provenance string between steps. No globals needed.
This commit is contained in:
parent
36bde60ba0
commit
92ca2bf2c8
7 changed files with 34 additions and 47 deletions
|
|
@ -37,7 +37,7 @@ pub use parse::{MemoryUnit, parse_units};
|
|||
pub use view::{StoreView, AnyView};
|
||||
pub use persist::fsck;
|
||||
pub use persist::strip_md_keys;
|
||||
pub use ops::{TASK_AGENT, set_phase};
|
||||
pub use ops::current_provenance;
|
||||
|
||||
use crate::graph::{self, Graph};
|
||||
|
||||
|
|
|
|||
|
|
@ -7,34 +7,11 @@ use super::types::*;
|
|||
|
||||
use std::collections::{HashMap, HashSet};
|
||||
|
||||
tokio::task_local! {
|
||||
/// Task-scoped agent name for provenance. Set before running an agent's
|
||||
/// tool calls, so all writes within that task are attributed to the agent.
|
||||
pub static TASK_AGENT: String;
|
||||
}
|
||||
|
||||
thread_local! {
|
||||
/// Current phase within a multi-step agent. Updated by the bail function
|
||||
/// between steps. Combined with TASK_AGENT to form the full provenance.
|
||||
static TASK_PHASE: std::cell::RefCell<Option<String>> = const { std::cell::RefCell::new(None) };
|
||||
}
|
||||
|
||||
/// Set the current phase (called from bail function between steps).
|
||||
pub fn set_phase(phase: &str) {
|
||||
TASK_PHASE.with(|p| *p.borrow_mut() = Some(phase.to_string()));
|
||||
}
|
||||
|
||||
/// Get the full provenance string: "agent:phase" or "agent" or env var or "manual".
|
||||
/// Fallback provenance for non-tool-dispatch paths (CLI, digest, etc.).
|
||||
/// Tool dispatch passes provenance directly through thought::dispatch.
|
||||
pub fn current_provenance() -> String {
|
||||
let agent = TASK_AGENT.try_with(|a| a.clone()).ok();
|
||||
let phase = TASK_PHASE.with(|p| p.borrow().clone());
|
||||
|
||||
match (agent, phase) {
|
||||
(Some(a), Some(p)) => format!("{}:{}", a, p),
|
||||
(Some(a), None) => a,
|
||||
_ => std::env::var("POC_PROVENANCE")
|
||||
.unwrap_or_else(|_| "manual".to_string()),
|
||||
}
|
||||
std::env::var("POC_PROVENANCE")
|
||||
.unwrap_or_else(|_| "manual".to_string())
|
||||
}
|
||||
|
||||
impl Store {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue