Skip to main content

llm/usage/
source.rs

1use schemars::JsonSchema;
2use serde::{Deserialize, Serialize};
3use uuid::Uuid;
4
5/// The agent a usage sample belongs to and where it sits in the sub-agent
6/// tree. A freshly created source has no parent; the agent that receives a
7/// sub-agent's usage fills in `parent_agent_id` and `task_id`.
8#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
9pub struct UsageSource {
10    pub agent_id: String,
11    pub parent_agent_id: Option<String>,
12    pub task_id: Option<String>,
13    pub agent_name: String,
14}
15
16impl UsageSource {
17    pub fn new(agent_name: impl Into<String>) -> Self {
18        Self {
19            agent_id: Uuid::new_v4().to_string(),
20            parent_agent_id: None,
21            task_id: None,
22            agent_name: agent_name.into(),
23        }
24    }
25}