hive-agent: export ACP-reported cost and context fill over OTLP
An ACP agent's `usage_update` carries `cost.{amount,currency}`, the
session's running total (opencode sums every assistant message in the
session). hive-runtime now reads it and turns the running total into
what each report added: a new session counts from zero, a session loaded
into a freshly started agent only baselines on its first report, and a
falling total adds nothing. The spend is held on the runtime until
`Runtime::take_reported_cost` drains it; claude's runtime reports none,
since the claude binary already exports `claude_code.cost.usage`.
hive-agent's existing turn-metrics meter records three new instruments:
- `hyperhive.agent.cost.usage` (counter, `model` + `currency`), ACP only;
- `hyperhive.agent.context.used` / `.size` (gauges, no attributes), for
every backend: the two numbers the web UI's ctx% divides.
The `hyperhive · agents` dashboard gets ACP cost panels on its cost tab
and a context-fill panel on its health tab.
Refs #4845
This commit is contained in:
parent
5d7042e655
commit
c2bdf30e05
8 changed files with 605 additions and 26 deletions
|
|
@ -23,7 +23,7 @@ mod spec;
|
|||
|
||||
pub use acp::{
|
||||
AcpError, AcpRuntime, Canceller, Choice, Choices, PermissionAsk, PermissionPolicy,
|
||||
SessionChoices,
|
||||
ReportedCost, SessionChoices,
|
||||
};
|
||||
pub use claude::ClaudeRuntime;
|
||||
pub use hive_claude::{
|
||||
|
|
@ -65,6 +65,11 @@ pub trait Runtime {
|
|||
/// pick. `None` for a runtime whose session offers none to read: claude's
|
||||
/// `--model` and `--effort` are passed through unchecked.
|
||||
fn choices(&self) -> Option<Choices>;
|
||||
|
||||
/// What the agent reported spending since the last call, one entry per
|
||||
/// currency. Empty for a runtime whose agent reports no cost: claude
|
||||
/// exports its own.
|
||||
fn take_reported_cost(&self) -> Vec<ReportedCost>;
|
||||
}
|
||||
|
||||
/// The runtime an agent was configured with, chosen at startup from a
|
||||
|
|
@ -109,6 +114,13 @@ impl<P: CompactionPolicy> Runtime for AgentRuntime<P> {
|
|||
Self::Acp(r) => r.choices(),
|
||||
}
|
||||
}
|
||||
|
||||
fn take_reported_cost(&self) -> Vec<ReportedCost> {
|
||||
match self {
|
||||
Self::Claude(r) => r.take_reported_cost(),
|
||||
Self::Acp(r) => r.take_reported_cost(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Why a runtime operation did not complete.
|
||||
|
|
|
|||
Loading…
Reference in a new issue