Skip to content

Commit 38a9057

Browse files
committed
[WIP] Builder; package metadata fields; README.md
1 parent 25d2d18 commit 38a9057

File tree

17 files changed

+205
-72
lines changed

17 files changed

+205
-72
lines changed

rust-sdk/TODO

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
* Agent "state" handling
2-
* Run parameters DX improvements
3-
* More elaborate error handling (especially for deserialization errors)
4-
* Retries?
5-
* Documentation
1+
- [ ] Agent "state" handling
2+
- [ ] Run parameters DX improvements
3+
- [ ] More elaborate error handling (especially for deserialization errors)
4+
- [ ] Retries?
5+
- [ ] Documentation
6+
- [ ] JSON Patch types in `ag-ui-core`
7+
- [ ] Builder patterns on most-used structs
8+
- [ ] Review EventHandler & Mutations
9+
- [ ] Subscriber + mutations DX improvement

rust-sdk/crates/ag-ui-client/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
name = "ag-ui-client"
33
version = "0.1.0"
44
edition = "2024"
5+
description = "Client library for the AG-UI protocol."
6+
license = "MIT"
7+
readme = "README.md"
58

69
[dependencies]
710
ag-ui-core = { path = "../ag-ui-core"}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# AG-UI Rust Client

rust-sdk/crates/ag-ui-client/examples/basic_agent.rs

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,36 @@
1+
use ag_ui_client::Agent;
12
use ag_ui_client::agent::{AgentError, RunAgentParams};
23
use ag_ui_client::http::HttpAgent;
3-
use reqwest::Url;
4-
use reqwest::header::{HeaderMap, HeaderValue};
54

6-
use ag_ui_client::Agent;
5+
use ag_ui_core::JsonValue;
76
use ag_ui_core::types::ids::MessageId;
87
use ag_ui_core::types::message::Message;
98
use log::info;
9+
use reqwest::Url;
1010

1111
#[tokio::main]
1212
async fn main() -> Result<(), AgentError> {
13-
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init();
14-
15-
// Create a base URL for the mock server
16-
// Note: Make sure the mock server is running on this address
17-
let base_url = Url::parse("http://127.0.0.1:3001/")
18-
.map_err(|e| AgentError::ConfigError {message: e.to_string() })?;
13+
env_logger::Builder::from_default_env().init();
1914

20-
// Create headers
21-
let mut headers = HeaderMap::new();
22-
headers.insert("Content-Type", HeaderValue::from_static("application/json"));
15+
// Base URL for the mock server
16+
// Run the following command to start the mock server:
17+
// `uv run rust-sdk/crates/ag-ui-client/scripts/basic_agent.py`
18+
let base_url = Url::parse("http://127.0.0.1:3001/").map_err(|e| AgentError::ConfigError {
19+
message: e.to_string(),
20+
})?;
2321

24-
// Create the HTTP agent
25-
let agent = HttpAgent::new(base_url, headers);
22+
// Create agent
23+
let agent = HttpAgent::builder().with_url(base_url).build()?;
2624

2725
// Create run parameters
28-
let params = RunAgentParams {
29-
run_id: None,
30-
tools: None,
31-
context: None,
26+
let params = RunAgentParams::<JsonValue, _> {
3227
forwarded_props: Some(serde_json::json!({})),
3328
messages: vec![Message::User {
3429
id: MessageId::random(),
3530
content: "Can you give me the current temperature in New York?".into(),
3631
name: None,
3732
}],
38-
state: serde_json::json!({}),
33+
..Default::default()
3934
};
4035

4136
info!("Running agent...");

rust-sdk/crates/ag-ui-client/examples/generative_ui.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,15 @@ where
152152

153153
#[tokio::main]
154154
async fn main() -> Result<(), Box<dyn Error>> {
155-
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init();
155+
env_logger::Builder::from_default_env().init();
156156

157+
// Base URL for the mock server
158+
// Run the following command to start the mock server:
159+
// `uv run rust-sdk/crates/ag-ui-client/scripts/generative_ui.py`
157160
let base_url = Url::parse("http://127.0.0.1:3001/")?;
158-
let headers = HeaderMap::new();
159161

160162
// Create the HTTP agent
161-
let agent = HttpAgent::new(base_url, headers);
163+
let agent = HttpAgent::builder().with_url(base_url).build()?;
162164

163165
let subscriber = GenerativeUiSubscriber::new();
164166

rust-sdk/crates/ag-ui-client/examples/logging_subscriber.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,14 @@ use std::fmt::Debug;
2727
#[tokio::main]
2828
async fn main() -> Result<(), Box<dyn Error>> {
2929
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init();
30-
// Create a base URL for the mock server
31-
// Note: Make sure the mock server is running on this address
32-
let base_url = Url::parse("http://127.0.0.1:3001/")?;
3330

34-
// Create headers
35-
let mut headers = HeaderMap::new();
36-
headers.insert("Content-Type", HeaderValue::from_static("application/json"));
31+
// Base URL for the mock server
32+
// Run the following command to start the mock server:
33+
// `uv run rust-sdk/crates/ag-ui-client/scripts/basic_agent.py`
34+
let base_url = Url::parse("http://127.0.0.1:3001/")?;
3735

3836
// Create the HTTP agent
39-
let agent = HttpAgent::new(base_url, headers);
37+
let agent = HttpAgent::builder().with_url(base_url).build()?;
4038

4139
// Create a simple subscriber
4240
let subscriber = LoggingSubscriber::new(true);

rust-sdk/crates/ag-ui-client/examples/shared_state.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@ use ag_ui_core::types::ids::MessageId;
66
use ag_ui_core::types::message::Message;
77
use ag_ui_core::{AgentState, FwdProps, JsonValue};
88
use async_trait::async_trait;
9+
910
use log::info;
1011
use reqwest::Url;
11-
use reqwest::header::{HeaderMap, HeaderValue};
1212
use serde::{Deserialize, Serialize};
1313
use std::error::Error;
1414
use std::fmt::{Debug, Display, Formatter};
15-
use std::sync::Arc;
1615

1716
#[derive(Serialize, Deserialize, Debug, Clone, Default, PartialEq, Eq, Hash)]
1817
pub enum SkillLevel {
@@ -146,13 +145,15 @@ where
146145

147146
#[tokio::main]
148147
async fn main() -> Result<(), Box<dyn Error>> {
149-
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init();
148+
env_logger::Builder::from_default_env().init();
150149

150+
// Base URL for the mock server
151+
// Run the following command to start the mock server:
152+
// `uv run rust-sdk/crates/ag-ui-client/scripts/shared_state.py`
151153
let base_url = Url::parse("http://127.0.0.1:3001/")?;
152-
let headers = HeaderMap::new();
153154

154155
// Create the HTTP agent
155-
let agent = HttpAgent::new(base_url, headers);
156+
let agent = HttpAgent::builder().with_url(base_url).build()?;
156157

157158
let subscriber = RecipeSubscriber::new();
158159

rust-sdk/crates/ag-ui-client/examples/sse_example.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use ag_ui_client::sse::SseResponseExt;
2-
use ag_ui_core::event::Event;
32
use futures::StreamExt;
43
use serde::Deserialize;
54
use std::error::Error;

rust-sdk/crates/ag-ui-client/src/agent.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ where
4141

4242
/// Parameters for running an agent.
4343
#[derive(Debug, Clone, Default)]
44-
pub struct RunAgentParams<StateT: AgentState, FwdPropsT = JsonValue> {
44+
pub struct RunAgentParams<StateT: AgentState = JsonValue, FwdPropsT: FwdProps = JsonValue> {
4545
pub run_id: Option<RunId>,
4646
pub tools: Option<Vec<Tool>>,
4747
pub context: Option<Vec<Context>>,
@@ -90,6 +90,7 @@ pub enum AgentError {
9090
},
9191
}
9292

93+
// TODO: Expand documentation
9394
/// Agent trait
9495
#[async_trait::async_trait]
9596
pub trait Agent<StateT = JsonValue, FwdPropsT = JsonValue>: Send + Sync
@@ -102,6 +103,7 @@ where
102103
input: &RunAgentInput<StateT, FwdPropsT>,
103104
) -> Result<EventStream<'async_trait, StateT>, AgentError>;
104105

106+
// TODO: Expand documentation
105107
/// The main execution method, containing the full pipeline logic.
106108
async fn run_agent(
107109
&self,

rust-sdk/crates/ag-ui-client/src/event_handler.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
use json_patch::PatchOperation;
2-
use serde_json::Value as JsonValue;
3-
use std::collections::{HashMap, HashSet};
4-
51
use ag_ui_core::event::Event;
62
use ag_ui_core::types::ids::MessageId;
73
use ag_ui_core::types::input::RunAgentInput;
84
use ag_ui_core::types::message::{FunctionCall, Message, Role};
95
use ag_ui_core::types::tool::ToolCall;
106
use ag_ui_core::{AgentState, FwdProps};
7+
use json_patch::PatchOperation;
8+
use log::error;
9+
use serde_json::Value as JsonValue;
10+
use std::collections::{HashMap, HashSet};
1111

1212
use crate::agent::{AgentError, AgentStateMutation};
1313
use crate::subscriber::{AgentSubscriberParams, Subscribers};
@@ -528,6 +528,7 @@ where
528528
}
529529

530530
pub async fn on_error(&self, error: &AgentError) -> Result<(), AgentError> {
531+
error!("Agent error: {error}");
531532
for subscriber in &self.subscribers {
532533
let _mutation = subscriber
533534
.on_run_failed(error, self.to_subscriber_params())

0 commit comments

Comments
 (0)