Rust agents
Agents contracts and source references for Rust.
Rust ToolLoopAgent::new accepts configuration, an Arc<dyn LanguageModel>, a tool registry, and an approval handler. run is asynchronous and returns a result. Streaming agents and ordinary tool loops are different types. Import the agent library directly, or use forge_sdk::agent; the aggregate crate is named forge_sdk, not forge.
A bounded run
This complete function accepts a model already configured by the caller. No tools are registered. Supply a model supported by your application and handle the returned error or exception at the caller. This example does not provision provider credentials, identity or deployment.
use std::sync::Arc;
use forge_agent::agent::{Agent, AgentConfig, AgentOutput};
use forge_agent::error::ForgeAgentError;
use forge_agent::tool_loop::ToolLoopAgent;
use forge_core::model::LanguageModel;
use forge_tool::approval::DenyAll;
use forge_tool::registry::ToolRegistry;
pub async fn run_agent(
model: Arc<dyn LanguageModel>,
provider_ref: &str,
prompt: &str,
) -> Result<AgentOutput, ForgeAgentError> {
let config = AgentConfig::new("reader", provider_ref).with_max_steps(3);
let agent = ToolLoopAgent::new(
config,
model,
ToolRegistry::new(),
Arc::new(DenyAll::new("No tools are authorized for this run")),
);
agent.run(prompt).await
}Rust reference
Each reference records the source path, hash and declaration inventory for this language. Start at the import boundary before using a symbol found in a deeper implementation file.
Lifecycle and failures
Choose finite iteration and token budgets, handle generation and execution failures, and release resources on termination. Inspect the returned usage and completion state before recording a successful run. The SDK health/lifecycle object describes local runtime state; it is not a deployment health check.