Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/sdk/rust/client/agent-trait.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ let params_typed = RunAgentParams::<MyState, MyProps>::new_typed()
Builder helpers include:

- with_run_id(run_id)
- with_parent_run_id(parent_run_id)
- with_resume(resume)
- add_tool(tool)
- add_context(ctx)
- with_forwarded_props(props)
Expand Down
5 changes: 4 additions & 1 deletion docs/sdk/rust/client/subscriber.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl AgentSubscriber for Logger {
_buffer: &str,
_params: ag_ui_client::subscriber::AgentSubscriberParams<'async_trait, serde_json::Value, serde_json::Value>,
) -> Result<ag_ui_client::agent::AgentStateMutation, ag_ui_client::agent::AgentError> {
println!("chunk: {}", event.content);
println!("chunk: {}", event.delta);
Ok(Default::default())
}
}
Expand Down Expand Up @@ -101,6 +101,9 @@ You can implement specific typed callbacks or the catch‑all on_event. Key call
- on_tool_call_start_event / on_tool_call_args_event / on_tool_call_end_event / on_tool_call_result_event
- on_state_snapshot_event / on_state_delta_event
- on_messages_snapshot_event
- on_activity_snapshot_event / on_activity_delta_event
- on_reasoning_start_event / on_reasoning_message_start_event / on_reasoning_message_content_event / on_reasoning_message_end_event
- on_reasoning_message_chunk_event / on_reasoning_end_event / on_reasoning_encrypted_value_event
- on_raw_event / on_custom_event

All callbacks have sensible defaults that return Ok(Default::default()). Only implement what you need.
Expand Down
21 changes: 19 additions & 2 deletions docs/sdk/rust/core/events.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,45 @@ pub enum Event<StateT> {
TextMessageEnd(TextMessageEndEvent),
TextMessageChunk(TextMessageChunkEvent),
ThinkingTextMessageStart(ThinkingTextMessageStartEvent),
ThinkingTextMessageContent(ThinkingTextMessageContentEvent),
ThinkingTextMessageEnd(ThinkingTextMessageEndEvent),
ToolCallStart(ToolCallStartEvent),
ToolCallArgs(ToolCallArgsEvent),
ToolCallEnd(ToolCallEndEvent),
ToolCallChunk(ToolCallChunkEvent),
ToolCallResult(ToolCallResultEvent),
StateSnapshot(StateSnapshotEvent<StateT>),
StateDelta(StateDeltaEvent),
MessagesSnapshot(MessagesSnapshotEvent),
ActivitySnapshot(ActivitySnapshotEvent),
ActivityDelta(ActivityDeltaEvent),
Raw(RawEvent),
Custom(CustomEvent),
ReasoningStart(ReasoningStartEvent),
ReasoningMessageStart(ReasoningMessageStartEvent),
ReasoningMessageContent(ReasoningMessageContentEvent),
ReasoningMessageEnd(ReasoningMessageEndEvent),
ReasoningMessageChunk(ReasoningMessageChunkEvent),
ReasoningEnd(ReasoningEndEvent),
ReasoningEncryptedValue(ReasoningEncryptedValueEvent),
}
```

## Frequently used events

- RunStartedEvent – signals the beginning of a run
- RunFinishedEvent – contains an optional result payload
- RunStartedEvent – signals the beginning of a run and can include parentRunId/input
- RunFinishedEvent – contains an optional result payload or interrupt-aware outcome
- RunErrorEvent – reports an error with message/context
- TextMessageStart/Content/End – streaming assistant message text
- TextMessageChunk – convenience chunk form matching the proto schema
- ToolCall* – tool call lifecycle and argument streaming
- StateSnapshotEvent<StateT> – full state replacement
- StateDeltaEvent – JSON-Patch style deltas (Vec<Value>)
- MessagesSnapshotEvent – full replacement of the message history
- ActivitySnapshotEvent/ActivityDeltaEvent – structured in-progress activity updates
- Reasoning* – reasoning block/message events and encrypted reasoning values

`Thinking*` events are still accepted for compatibility, but the protocol docs now mark them as deprecated in favor of the `Reasoning*` events.

## Handling in subscribers

Expand Down
11 changes: 7 additions & 4 deletions docs/sdk/rust/core/types.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,19 @@ let tcid = ToolCallId::random();

## Messages

Message is an enum covering different roles. Helpers exist to create messages.
Message is an enum covering protocol roles: developer, system, assistant, user, tool, activity, and reasoning. Helpers exist to create common message types.

```rust
use ag_ui_client::core::types::{Message, MessageId};
use ag_ui_client::core::types::Message;

let user = Message::new_user("Hello");
let system = Message::new_system("You are a helpful assistant");
let dev = Message::new_developer("internal instruction");
let tool = Message::new_tool("result", ag_ui_client::core::types::ToolCallId::random());
let tool = Message::new_tool("result");
```

Each variant also has a builder form; see crate docs for full fields (name, error, tool call reference, etc.).
Activity messages carry structured JSON content for in-progress UI state. Reasoning messages carry reasoning content and optional encryptedValue.

## Tools and context

Expand All @@ -60,6 +61,8 @@ let tool = Tool::new(
let ctx = Context::new("trace_id".into(), "abc-123".into());
```

Tools can also carry optional metadata, and tool calls can carry encryptedValue for reasoning continuity workflows.

## RunAgentInput

The payload sent to an agent, typically over HTTP by HttpAgent. Constructed internally by Agent::run_agent but also available directly.
Expand All @@ -79,7 +82,7 @@ let input = RunAgentInput::new(
);
```

Type parameters allow strongly-typed state and forwarded_props when desired.
Type parameters allow strongly-typed state and forwarded_props when desired. Use `with_parent_run_id` to record run lineage and `with_resume` to resume interrupts with `ResumeEntry` values.

## Traits: AgentState and FwdProps

Expand Down
17 changes: 16 additions & 1 deletion sdks/community/rust/crates/ag-ui-client/src/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::collections::HashSet;

use crate::core::JsonValue;
use crate::core::types::{
AgentId, Context, Message, MessageId, RunAgentInput, RunId, ThreadId, Tool,
AgentId, Context, Message, MessageId, ResumeEntry, RunAgentInput, RunId, ThreadId, Tool,
};
use crate::core::{AgentState, FwdProps};
use crate::event_handler::EventHandler;
Expand Down Expand Up @@ -41,11 +41,13 @@ where
#[derive(Debug, Clone, Default)]
pub struct RunAgentParams<StateT: AgentState = JsonValue, FwdPropsT: FwdProps = JsonValue> {
pub run_id: Option<RunId>,
pub parent_run_id: Option<RunId>,
pub tools: Vec<Tool>,
pub context: Vec<Context>,
pub forwarded_props: FwdPropsT,
pub messages: Vec<Message>,
pub state: StateT,
pub resume: Option<Vec<ResumeEntry>>,
}

impl<StateT, FwdPropsT> RunAgentParams<StateT, FwdPropsT>
Expand All @@ -60,18 +62,28 @@ where
pub fn new_typed() -> Self {
Self {
run_id: None,
parent_run_id: None,
tools: Vec::new(),
context: Vec::new(),
forwarded_props: FwdPropsT::default(),
messages: Vec::new(),
state: StateT::default(),
resume: None,
}
}

pub fn with_run_id(mut self, run_id: RunId) -> Self {
self.run_id = Some(run_id);
self
}
pub fn with_parent_run_id(mut self, parent_run_id: RunId) -> Self {
self.parent_run_id = Some(parent_run_id);
self
}
pub fn with_resume(mut self, resume: Vec<ResumeEntry>) -> Self {
self.resume = Some(resume);
self
}
pub fn add_tool(mut self, tool: Tool) -> Self {
self.tools.push(tool);
self
Expand All @@ -97,6 +109,7 @@ where
id: MessageId::random(),
content: content.into(),
name: None,
encrypted_value: None,
});
self
}
Expand Down Expand Up @@ -192,11 +205,13 @@ where
let input = RunAgentInput {
thread_id: ThreadId::random(),
run_id: params.run_id.clone().unwrap_or_else(RunId::random),
parent_run_id: params.parent_run_id.clone(),
state: params.state.clone(),
messages: params.messages.clone(),
tools: params.tools.clone(),
context: params.context.clone(),
forwarded_props: params.forwarded_props.clone(),
resume: params.resume.clone(),
};
let current_message_ids: HashSet<&MessageId> =
params.messages.iter().map(|m| m.id()).collect();
Expand Down
Loading