story-kit: merge 296_story_track_per_agent_token_usage_for_cost_visibility_and_optimisation
This commit is contained in:
@@ -500,7 +500,24 @@ impl AgentPool {
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(session_id) => {
|
||||
Ok(pty_result) => {
|
||||
// Persist token usage if the agent reported it.
|
||||
if let Some(ref usage) = pty_result.token_usage
|
||||
&& let Ok(agents) = agents_ref.lock()
|
||||
&& let Some(agent) = agents.get(&key_clone)
|
||||
&& let Some(ref pr) = agent.project_root
|
||||
{
|
||||
let record = super::token_usage::build_record(
|
||||
&sid, &aname, usage.clone(),
|
||||
);
|
||||
if let Err(e) = super::token_usage::append_record(pr, &record) {
|
||||
slog_error!(
|
||||
"[agents] Failed to persist token usage for \
|
||||
{sid}:{aname}: {e}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Server-owned completion: run acceptance gates automatically
|
||||
// when the agent process exits normally.
|
||||
run_server_owned_completion(
|
||||
@@ -508,7 +525,7 @@ impl AgentPool {
|
||||
port_for_task,
|
||||
&sid,
|
||||
&aname,
|
||||
session_id,
|
||||
pty_result.session_id,
|
||||
watcher_tx_clone.clone(),
|
||||
)
|
||||
.await;
|
||||
|
||||
Reference in New Issue
Block a user