1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
//! Drive Claude Code, Codex and GitHub Copilot headlessly from Rust.
//!
//! One request type, one event vocabulary and one session model across three
//! agent CLIs that agree on none of those things. This is a **library**: your
//! program links it and spawns the agent itself, with no intermediate CLI
//! marshalling a request through stdout and back.
//!
//! # Running a prompt
//!
//! ```no_run
//! use agent_abstraction::{Agent, Permission, Request, run};
//!
//! # async fn example() -> agent_abstraction::Result<()> {
//! let outcome = run(
//! &Request::new(Agent::Claude, "Reply with the single word: pong")
//! .model("haiku")
//! .permission(Permission::ReadOnly),
//! )
//! .await?;
//!
//! println!("{}", outcome.text);
//! # Ok(())
//! # }
//! ```
//!
//! # Watching one as it works
//!
//! ```no_run
//! use agent_abstraction::{Agent, Event, Request, stream};
//!
//! # async fn example() -> agent_abstraction::Result<()> {
//! let mut running = stream(&Request::new(Agent::Claude, "audit this repo"))?;
//! while let Some(event) = running.recv().await {
//! match event {
//! Event::Text(text) => print!("{text}"),
//! Event::ToolCall { name, .. } => println!("[{name}]"),
//! _ => {}
//! }
//! }
//! let outcome = running.finish().await?;
//! # Ok(())
//! # }
//! ```
//!
//! # Multi-turn conversations
//!
//! Thread one stable name across turns and let [`SessionStore`] map it to
//! whatever handle the agent understands:
//!
//! ```no_run
//! use agent_abstraction::{Agent, Request, SessionStore, run};
//!
//! # async fn example() -> agent_abstraction::Result<()> {
//! let store = SessionStore::open("/var/lib/myapp/sessions");
//!
//! // First turn creates the session; later turns continue it.
//! let first = Request::new(Agent::Claude, "remember the number 7")
//! .session(&store, ".", "thread-42", false)?;
//! run(&first).await?;
//!
//! let second = Request::new(Agent::Claude, "what number did I say?")
//! .session(&store, ".", "thread-42", false)?;
//! println!("{}", run(&second).await?.text);
//! # Ok(())
//! # }
//! ```
//!
//! # What each agent can do
//!
//! | | session id | fork | events | system prompt |
//! |---|---|---|---|---|
//! | Claude Code | caller-minted (`--session-id`) | yes | yes | native flag |
//! | Codex | agent-printed (`thread_id`) | no | yes | prepended |
//! | Copilot | caller-minted (`--session-id`) | no | yes | prepended |
//!
//! Asking for something an agent cannot do is always an [`Error::Unsupported`],
//! never a silent downgrade. A caller that asked to fork and got a linear
//! resume would corrupt the conversation it meant to branch.
//!
//! # Operating within the agents' terms
//!
//! This crate drives each vendor's own supported headless interface with the
//! credentials that CLI already uses. It does not reimplement a provider API,
//! multiplex accounts, or retry around a quota: a refusal surfaces as
//! [`Error::RateLimited`], carrying the provider's own wording, and backing off
//! is the caller's decision. See `docs/operating-limits.md`.
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use Request;
pub use ;
pub use ;