adk_server/agent_engine/envelope.rs
1//! Wire envelope for the Agent Engine dispatch protocol.
2//!
3//! # Casing exception
4//!
5//! This envelope is **snake_case**, not the workspace's usual camelCase for
6//! REST payloads. The platform's container contract dispatches
7//! `{"class_method": ..., "input": ...}` because adk-python resolves the
8//! method with `getattr` — the field names are Python identifiers on the
9//! wire (confirmed by verification task V14). Do not "fix" this to
10//! camelCase; it would break every host-side caller.
11
12use serde::Deserialize;
13use serde_json::{Value, json};
14
15/// A dispatch request as delivered by the Agent Engine host to the container.
16///
17/// Sent to both `POST /api/reasoning_engine` (unary) and
18/// `POST /api/stream_reasoning_engine` (streaming).
19///
20/// # Example
21///
22/// ```rust
23/// use adk_server::agent_engine::DispatchRequest;
24///
25/// let req: DispatchRequest = serde_json::from_str(
26/// r#"{"class_method": "async_stream_query", "input": {"user_id": "u", "message": "hi"}}"#,
27/// )
28/// .unwrap();
29/// assert_eq!(req.class_method, "async_stream_query");
30/// ```
31#[derive(Debug, Clone, Deserialize)]
32pub struct DispatchRequest {
33 /// The operation name, matched against [`ClassMethod`](super::ClassMethod).
34 pub class_method: String,
35 /// Operation arguments; each class method deserializes this into its
36 /// typed input struct at the dispatch boundary.
37 pub input: Option<Value>,
38}
39
40/// Wraps a unary handler result in the platform's `{"output": ...}` envelope.
41pub(crate) fn unary_response(output: Value) -> Value {
42 json!({ "output": output })
43}