pub struct CallContext { /* private fields */ }Expand description
The tracked call a tool is running in. The SDK puts one into the request context of every tool
call it passes to the handler, so a tool can take it as an Extension<CallContext> (rmcp’s
rmcp::handler::server::common::Extension) next to its parameters. A call the SDK does not
trace (tracing off, no session ID could be issued, or AGENTCAT_ENABLED turned the SDK off)
gets one too, with no session and no agent.
use agentcat_sdk::CallContext;
use rmcp::handler::server::common::Extension;
// A parameter of a `#[tool]` method, next to its `Parameters<..>`.
fn session_of(Extension(call): Extension<CallContext>) -> String {
call.session_id().unwrap_or("no session").to_owned()
}Implementations§
Source§impl CallContext
impl CallContext
Sourcepub fn session_id(&self) -> Option<&str>
pub fn session_id(&self) -> Option<&str>
The session ID the call belongs to: the one the agent sent, or the one the SDK issued for
this call. None when the call has no session: the agent sent a value this server did not
issue, the tool declares its own session_id parameter, or the SDK does not trace the
call. Also always None with a
resolve_session_id hook set: the hook decides the
session after the call starts, so the context has none.
Source§impl CallContext
impl CallContext
Sourcepub fn publish_custom_event(
&self,
project_id: &str,
event: CustomEvent,
) -> Result<(), Error>
pub fn publish_custom_event( &self, project_id: &str, event: CustomEvent, ) -> Result<(), Error>
Publishes a custom event with this call’s client and server identity, as a tracked server publishes it. It only queues the event, so it returns at once.
The event goes to the project of the handle (AgentCat::new), not
to project_id, which only has to be non-empty. Nothing is queued while tracing is off, or
by a handle that AGENTCAT_ENABLED turned off. The redact_event hook of the options runs
on the event, on the runtime of the caller; the string hook does not. The event has no
session unless the CustomEvent names one: it takes none from the call. Pass
session_id() in the CustomEvent to attribute the event to the
call’s session. A duration of zero or none is the time since
the event was built.
use agentcat_sdk::CustomEvent;
let mut event = CustomEvent::new().resource_name("cache-warmed");
if let Some(session) = call.session_id() {
event = event.session_id(session);
}
call.publish_custom_event("proj_123", event)?;§Errors
Error::ProjectIdRequired when project_id is empty, except on a handle that
AGENTCAT_ENABLED turned off, which returns Ok(()) and does nothing.