codex_extension_api/capabilities/
agent.rs1use std::future::Future;
2use std::pin::Pin;
3
4use codex_protocol::ThreadId;
5
6pub type AgentSpawnFuture<'a, T, E> = Pin<Box<dyn Future<Output = Result<T, E>> + Send + 'a>>;
8
9pub trait AgentSpawner<R>: Send + Sync {
14 type Spawned;
15 type Error;
16
17 fn spawn_subagent<'a>(
18 &'a self,
19 forked_from_thread_id: ThreadId,
20 request: R,
21 ) -> AgentSpawnFuture<'a, Self::Spawned, Self::Error>;
22}
23
24impl<R, S, E, F> AgentSpawner<R> for F
25where
26 F: Fn(ThreadId, R) -> AgentSpawnFuture<'static, S, E> + Send + Sync,
27{
28 type Spawned = S;
29 type Error = E;
30
31 fn spawn_subagent<'a>(
32 &'a self,
33 forked_from_thread_id: ThreadId,
34 request: R,
35 ) -> AgentSpawnFuture<'a, Self::Spawned, Self::Error> {
36 self(forked_from_thread_id, request)
37 }
38}