Skip to main content

Crate azure_ai_foundry_agents

Crate azure_ai_foundry_agents 

Source
Expand description

§azure_ai_foundry_agents

Crates.io docs.rs License: MIT

Agent Service client for the Azure AI Foundry Rust SDK.

§Features

  • Agents — Create, get, list, update, and delete AI agents
  • Threads — Manage conversation threads (create, get, update, delete)
  • Messages — Add, list, get, and update messages in threads
  • Runs — Execute agents, poll for completion, submit tool outputs
  • Files — Upload, download, list, and delete files
  • Vector Stores — CRUD operations for vector stores, files, and file batches
  • Run Steps — Inspect individual actions taken during a run
  • Tracing — Full instrumentation with tracing spans

§Installation

[dependencies]
azure_ai_foundry_core = "0.8"
azure_ai_foundry_agents = "0.8"
tokio = { version = "1", features = ["full"] }

§Usage

§Create an Agent

use azure_ai_foundry_core::client::FoundryClient;
use azure_ai_foundry_core::auth::FoundryCredential;
use azure_ai_foundry_agents::agent::{self, AgentCreateRequest};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = FoundryClient::builder()
        .endpoint("https://your-resource.services.ai.azure.com")
        .credential(FoundryCredential::api_key("your-key"))
        .build()?;

    let request = AgentCreateRequest::builder()
        .model("gpt-4o")
        .name("My Assistant")
        .instructions("You are a helpful assistant.")
        .try_build()?;

    let agent = agent::create(&client, &request).await?;
    println!("Created agent: {}", agent.id);
    Ok(())
}

§Run a Conversation

use azure_ai_foundry_core::client::FoundryClient;
use azure_ai_foundry_agents::{thread, message, run};
use azure_ai_foundry_agents::message::MessageCreateRequest;
use azure_ai_foundry_agents::run::RunCreateRequest;
use std::time::Duration;

// Create a thread
let thread = thread::create(client, None).await?;

// Add a message
let msg_request = MessageCreateRequest::builder()
    .content("What is the weather in Paris?")
    .try_build()?;
message::create(client, &thread.id, &msg_request).await?;

// Run the agent
let run_request = RunCreateRequest::builder()
    .assistant_id(agent_id)
    .try_build()?;
let created_run = run::create(client, &thread.id, &run_request).await?;

// Poll until complete (None = unlimited attempts)
let completed_run = run::poll_until_complete(
    client,
    &thread.id,
    &created_run.id,
    Duration::from_secs(1),
    None,
).await?;

// Get the response
let messages = message::list(client, &thread.id).await?;
println!("Response: {:?}", messages.data[0].content);

§Upload and Manage Files

use azure_ai_foundry_core::client::FoundryClient;
use azure_ai_foundry_agents::file::{self, FilePurpose};

// Upload a file
let file = file::upload(client, "data.jsonl", b"content".to_vec(), FilePurpose::Assistants).await?;

// Download file content
let content = file::download(client, &file.id).await?;

// List all files
let files = file::list(client).await?;

// Delete a file
file::delete(client, &file.id).await?;

§Vector Stores (RAG)

use azure_ai_foundry_core::client::FoundryClient;
use azure_ai_foundry_agents::vector_store::{self, VectorStoreCreateRequest};

// Create a vector store
let request = VectorStoreCreateRequest::builder()
    .name("My Knowledge Base")
    .build();
let store = vector_store::create(client, &request).await?;

// Add files to the vector store
vector_store::add_file(client, &store.id, "file-abc123").await?;

// Create a file batch
let batch = vector_store::create_file_batch(client, &store.id, &["file-1", "file-2"]).await?;

§Submit Tool Outputs

use azure_ai_foundry_core::client::FoundryClient;
use azure_ai_foundry_agents::run::{self, ToolOutput};
use std::time::Duration;

let outputs = vec![ToolOutput {
    tool_call_id: "call_abc".to_string(),
    output: "Sunny, 72°F".to_string(),
}];

let run = run::submit_tool_outputs_and_poll(
    client, "thread_xyz", "run_abc", &outputs, Duration::from_secs(1), Some(60),
).await?;

§Modules

ModuleDescription
agentCreate, get, list, update, delete agents
threadCreate, get, update, delete conversation threads
messageCreate, list, get, update messages in threads
runExecute agents, poll, submit tool outputs
fileUpload, download, list, delete files
vector_storeVector stores, files, and file batches
run_stepInspect run step details

§Tracing Spans

All API calls emit tracing spans for observability:

SpanFields
foundry::agents::createmodel
foundry::agents::getagent_id
foundry::agents::list-
foundry::agents::deleteagent_id
foundry::agents::updateagent_id
foundry::threads::create-
foundry::threads::getthread_id
foundry::threads::deletethread_id
foundry::threads::updatethread_id
foundry::messages::createthread_id
foundry::messages::listthread_id
foundry::messages::getthread_id, message_id
foundry::messages::updatethread_id, message_id
foundry::runs::createthread_id, assistant_id
foundry::runs::getthread_id, run_id
foundry::runs::create_thread_and_runassistant_id
foundry::runs::poll_until_completethread_id, run_id
foundry::runs::create_and_pollassistant_id
foundry::runs::submit_tool_outputsthread_id, run_id, output_count
foundry::runs::submit_tool_outputs_and_pollthread_id, run_id, output_count
foundry::files::uploadfilename, purpose
foundry::files::getfile_id
foundry::files::list-
foundry::files::deletefile_id
foundry::files::downloadfile_id
foundry::vector_stores::create-
foundry::vector_stores::getvector_store_id
foundry::vector_stores::list-
foundry::vector_stores::updatevector_store_id
foundry::vector_stores::deletevector_store_id
foundry::vector_stores::add_filevector_store_id, file_id
foundry::vector_stores::list_filesvector_store_id
foundry::vector_stores::get_filevector_store_id, file_id
foundry::vector_stores::delete_filevector_store_id, file_id
foundry::vector_stores::create_file_batchvector_store_id
foundry::vector_stores::get_file_batchvector_store_id, batch_id
foundry::run_steps::listthread_id, run_id
foundry::run_steps::getthread_id, run_id, step_id

§License

This project is licensed under the MIT License.

Modules§

agent
Agent management for Azure AI Foundry Agent Service.
file
File management for Azure AI Foundry Agent Service.
message
Message management for Azure AI Foundry Agent Service.
models
Shared types for the Azure AI Foundry Agent Service.
run
Run execution for Azure AI Foundry Agent Service.
run_step
Run step inspection for Azure AI Foundry Agent Service.
thread
Thread management for Azure AI Foundry Agent Service.
vector_store
Vector store management for Azure AI Foundry Agent Service.