simple_agents_core/lib.rs
1//! Core client API for SimpleAgents.
2//!
3//! This crate provides the unified `SimpleAgentsClient` that integrates
4//! providers and healing in one place.
5//!
6//! # Example
7//! ```no_run
8//! use simple_agents_core::{
9//! CompletionOptions, CompletionOutcome, SimpleAgentsClient,
10//! };
11//! use simple_agent_type::prelude::*;
12//! # use async_trait::async_trait;
13//! # use std::sync::Arc;
14//! #
15//! # struct MockProvider;
16//! #
17//! # #[async_trait]
18//! # impl Provider for MockProvider {
19//! # fn name(&self) -> &str { "mock" }
20//! # fn transform_request(&self, _req: &CompletionRequest) -> Result<ProviderRequest> {
21//! # Ok(ProviderRequest::new("http://example.com"))
22//! # }
23//! # async fn execute(&self, _req: ProviderRequest) -> Result<ProviderResponse> {
24//! # Ok(ProviderResponse::new(200, serde_json::json!({"ok": true})))
25//! # }
26//! # fn transform_response(&self, _resp: ProviderResponse) -> Result<CompletionResponse> {
27//! # Ok(CompletionResponse {
28//! # id: "resp_1".to_string(),
29//! # model: "test".to_string(),
30//! # choices: vec![CompletionChoice {
31//! # index: 0,
32//! # message: Message::assistant("ok"),
33//! # finish_reason: FinishReason::Stop,
34//! # logprobs: None,
35//! # }],
36//! # usage: Usage::new(1, 1),
37//! # created: None,
38//! # provider: Some("mock".to_string()),
39//! # healing_metadata: None,
40//! # })
41//! # }
42//! # }
43//! #
44//! # async fn example() -> Result<()> {
45//! let client = SimpleAgentsClient::new(Arc::new(MockProvider));
46//!
47//! let request = CompletionRequest::builder()
48//! .model("gpt-4")
49//! .message(Message::user("Hello!"))
50//! .build()?;
51//!
52//! let outcome = client.complete(&request, CompletionOptions::default()).await?;
53//! let response = match outcome {
54//! CompletionOutcome::Response(response) => response,
55//! _ => return Ok(()),
56//! };
57//! println!("{}", response.content().unwrap_or_default());
58//! # Ok(())
59//! # }
60//! ```
61
62#![deny(missing_docs)]
63#![deny(unsafe_code)]
64
65mod client;
66mod healing;
67
68pub use client::{
69 ClientConfig, CompletionMode, CompletionOptions, CompletionOutcome, ExecutionFlags,
70 RetryConfig, RunOptions, SimpleAgentsClient,
71};
72pub use healing::{HealedJsonResponse, HealedSchemaResponse, HealingSettings};
73
74// Re-export commonly used types.
75pub use simple_agent_type::prelude;