Skip to content
Merged
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
31 changes: 18 additions & 13 deletions examples/lead-agent/backend-rust/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ use axum::{
use serde::{Deserialize, Serialize};
use serde_json::{json, Value};
use tower_http::cors::{CorsLayer, AllowOrigin};
use runagent::{RunAgentClient, RunAgentClientConfig};

// RunAgent configuration
const RUNAGENT_ID: &str = "bd87871d-b4c4-4ec1-990b-bef0ea4766f7";
const RUNAGENT_ID: &str = "be87871d-b4c4-4ec1-990b-bef0ea4766f7";

// Request/Response types
#[derive(Deserialize)]
Expand Down Expand Up @@ -107,11 +108,13 @@ async fn score_leads(
}

// Initialize RunAgent client using configured agent ID
let client = match runagent::client::RunAgentClient::new(
RUNAGENT_ID,
"lead_score_flow",
false, // Set to false when using RunAgent Cloud
)
// API key will be picked up from RUNAGENT_API_KEY environment variable
let client = match RunAgentClient::new(RunAgentClientConfig {
agent_id: RUNAGENT_ID.to_string(),
entrypoint_tag: "lead_score_flow".to_string(),
local: Some(false), // Set to false when using RunAgent Cloud
..RunAgentClientConfig::default()
})
.await
{
Ok(client) => client,
Expand Down Expand Up @@ -144,7 +147,7 @@ async fn score_leads(
params.push(("candidates", json!(normalized_candidates)));

// Run the lead scoring flow
match client.run_with_args(&[], &params).await {
match client.run(&params).await {
Ok(result) => {
// Debug: Log the result structure
println!("[DEBUG] Agent result type: {}", result);
Expand Down Expand Up @@ -215,11 +218,13 @@ async fn score_single(
}

// Initialize RunAgent client using configured agent ID
let client = match runagent::client::RunAgentClient::new(
RUNAGENT_ID,
"score_candidate",
true, // local = true for single candidate scoring
)
// For local agents, API key is optional
let client = match RunAgentClient::new(RunAgentClientConfig {
agent_id: RUNAGENT_ID.to_string(),
entrypoint_tag: "score_candidate".to_string(),
local: Some(true), // local = true for single candidate scoring
..RunAgentClientConfig::default()
})
.await
{
Ok(client) => client,
Expand Down Expand Up @@ -252,7 +257,7 @@ async fn score_single(
}

// Score single candidate
match client.run_with_args(&[], &params).await {
match client.run(&params).await {
Ok(result) => Ok(JsonResponse(result)),
Err(e) => {
eprintln!("Error in score_single_candidate: {:?}", e);
Expand Down
2 changes: 1 addition & 1 deletion examples/lead-agent/lead-score-flow/runagent.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
]
},
"env_vars": {},
"agent_id": "bd87871d-b4c4-4ec1-990b-bef0ea4766f7",
"agent_id": "be87871d-b4c4-4ec1-990b-bef0ea4766f7",
"auth_settings": {
"type": "api_key"
}
Expand Down
49 changes: 49 additions & 0 deletions runagent-rust/PUBLISH.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Publishing the Rust SDK (`runagent-rust/runagent`)

Follow this checklist whenever you cut a new release of the Rust SDK.

## 1. Prerequisites

- Cargo credentials with publish rights to `runagent`.
- `cargo login <token>` already configured on the machine/CI runner.
- Clean git tree (all changes committed).

## 2. Version Bump

1. Update `version` in `runagent-rust/runagent/Cargo.toml`.
2. Update `runagent-rust/Cargo.toml` (workspace) if needed.
3. Update the version badge/examples in `runagent-rust/runagent/README.md`.

## 3. Build & Test

```bash
cd runagent-rust/runagent
cargo fmt
cargo clippy --all-targets --all-features -- -D warnings
cargo test --all-features
```

Optional: exercise key examples (local + remote) before publishing.

## 4. Package Audit

```bash
cargo package
```

Inspect `target/package/runagent-*.crate` (or run `cargo package --list`) to ensure only the expected files are included.

## 5. Publish

```bash
cargo publish
```

If 2FA is enabled, be ready to provide the OTP.

## 6. Post-Publish

- Tag the release: `git tag runagent-rust-vX.Y.Z && git push origin runagent-rust-vX.Y.Z`.
- Update release notes / changelog as needed.
- Ensure docs (README, SDK checklist) reflect any new behavior.

27 changes: 27 additions & 0 deletions runagent-rust/examples/async_example.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//! Async example using RunAgentClient
//!
//! This is the recommended approach for most use cases.

use runagent::{RunAgentClient, RunAgentClientConfig};
use serde_json::json;

#[tokio::main]
async fn main() -> runagent::RunAgentResult<()> {
// dotenvy::from_filename("local.env").ok(); // optional

let agent_id = "a6977384-6c88-40dc-a629-e6bf077786ae";
let entrypoint_tag = "minimal";

let client = RunAgentClient::new(
RunAgentClientConfig::new(agent_id, entrypoint_tag)
.with_local(true)
.with_address("127.0.0.1", 8452)
.with_enable_registry(false) // Skip DB lookup since we have explicit address
).await?;

let response = client.run(&[("message", json!("Hello!"))]).await?;

println!("Response: {}", response);
Ok(())
}

28 changes: 28 additions & 0 deletions runagent-rust/examples/direct_construction.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//! Example showing direct struct construction (TypeScript-like interface)
//!
//! This matches the TypeScript SDK pattern where you pass a config object directly.

use runagent::RunAgentClient;
use serde_json::json;

#[tokio::main]
async fn main() -> runagent::RunAgentResult<()> {
// Direct struct construction - matches TypeScript interface
let client = RunAgentClient::new(runagent::RunAgentClientConfig {
agent_id: "a6977384-6c88-40dc-a629-e6bf077786ae".to_string(),
entrypoint_tag: "minimal".to_string(),
api_key: Some("rau_b4dcebdef6386726b08971a1cc968d8a2b77c5834d30f3f5a43bddf065cd95cb".to_string()),
base_url: Some("http://localhost:8333/".to_string()),
local: None,
host: None,
port: None,
extra_params: None,
enable_registry: None,
}).await?;

let response = client.run(&[("message", json!("Hello!"))]).await?;

println!("Response: {}", response);
Ok(())
}
Comment on lines +1 to +27
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Remove hard-coded API key from the example to avoid secret exposure

This example currently embeds a full api_key literal:

api_key: Some("rau_...".to_string()),

Committing anything that looks like a real API key (even if test-only) is risky and will train users into copying the pattern. It’s safer to:

  • Read the key from an environment variable (e.g., std::env::var(ENV_RUNAGENT_API_KEY)) or
  • Use a placeholder like None / "YOUR_API_KEY_HERE".to_string() and explain in comments how to configure it.

I’d strongly recommend stripping or rotating any real key before merging.

🤖 Prompt for AI Agents
In runagent-rust/examples/direct_construction.rs around lines 1 to 27, remove
the hard-coded api_key literal and replace it with a non-secret pattern: read
the API key from an environment variable (e.g.,
std::env::var("RUNAGENT_API_KEY")) and pass that value as Some(key) if present,
or use None / a clear placeholder like "YOUR_API_KEY_HERE" when not set; ensure
you handle the Result from env::var (map to Option) or fall back safely so the
example compiles and does not expose secrets.


27 changes: 27 additions & 0 deletions runagent-rust/examples/sync_example.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//! Sync example using blocking RunAgentClient
//!
//! This is useful for simple scripts or when you can't use async/await.
//! Note: For better performance, prefer the async version.

use runagent::blocking::{RunAgentClient, RunAgentClientConfig};
use serde_json::json;

fn main() -> runagent::RunAgentResult<()> {
// dotenvy::from_filename("local.env").ok(); // optional

let agent_id = "a6977384-6c88-40dc-a629-e6bf077786ae";
let entrypoint_tag = "minimal";

let client = RunAgentClient::new(
RunAgentClientConfig::new(agent_id, entrypoint_tag)
.with_local(true)
.with_address("127.0.0.1", 8452)
.with_enable_registry(false) // Skip DB lookup since we have explicit address
)?;

let response = client.run(&[("message", json!("Hello!"))])?;

println!("Response: {}", response);
Ok(())
}

2 changes: 1 addition & 1 deletion runagent-rust/runagent/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "runagent"
version = "0.1.33"
version = "0.1.34"
edition = "2021"
description = "RunAgent SDK for Rust - Client SDK for interacting with deployed AI agents"
license = "MIT"
Expand Down
Loading