mirror of
https://github.com/openai/codex.git
synced 2026-09-11 20:36:49 +00:00
## What changed - Add `codex-agent-extension` with an `AgentRunner` that starts a resolved agent prompt in a thread forked from its parent. - Propagate the invocation's trace context, select the configured execution environments, submit the initial prompt, and return the spawned thread and turn identifiers. - Reject empty agent prompts and report when the owning thread manager is no longer available. ## Testing - Add an integration test that verifies the agent runs in a forked thread, returns the started turn identifier, completes the turn, and sends the resolved prompt to the model. GitOrigin-RevId: ffb805efabadf758969d6611a6867db6fa9f059a
71 lines
2.2 KiB
Rust
71 lines
2.2 KiB
Rust
use anyhow::Result;
|
|
use codex_agent_extension::AgentInvocation;
|
|
use codex_agent_extension::AgentRunner;
|
|
use codex_protocol::protocol::EventMsg;
|
|
use core_test_support::responses;
|
|
use core_test_support::skip_if_no_network;
|
|
use core_test_support::test_codex::test_codex;
|
|
use core_test_support::wait_for_event;
|
|
use pretty_assertions::assert_eq;
|
|
|
|
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
|
async fn starts_resolved_agent_prompt_in_forked_thread() -> Result<()> {
|
|
skip_if_no_network!(Ok(()));
|
|
|
|
let server = responses::start_mock_server().await;
|
|
let response_mock = responses::mount_sse_once(
|
|
&server,
|
|
responses::sse(vec![
|
|
responses::ev_response_created("agent-response"),
|
|
responses::ev_completed("agent-response"),
|
|
]),
|
|
)
|
|
.await;
|
|
let test = test_codex().build_with_auto_env(&server).await?;
|
|
let parent_thread_id = test.session_configured.session_id.into();
|
|
let agent_runner = AgentRunner::new(std::sync::Arc::downgrade(&test.thread_manager));
|
|
|
|
let agent_run = agent_runner
|
|
.start(
|
|
parent_thread_id,
|
|
AgentInvocation {
|
|
config: test.config.clone(),
|
|
prompt: "Use $example-agent to inspect the current changes.".to_string(),
|
|
parent_trace: None,
|
|
},
|
|
)
|
|
.await?;
|
|
|
|
assert_ne!(agent_run.thread_id, parent_thread_id);
|
|
assert_eq!(
|
|
agent_run
|
|
.thread
|
|
.config_snapshot()
|
|
.await
|
|
.forked_from_thread_id,
|
|
Some(parent_thread_id)
|
|
);
|
|
let started = wait_for_event(&agent_run.thread, |event| {
|
|
matches!(event, EventMsg::TurnStarted(_))
|
|
})
|
|
.await;
|
|
let EventMsg::TurnStarted(started) = started else {
|
|
unreachable!("event predicate only matches turn started events");
|
|
};
|
|
assert_eq!(started.turn_id, agent_run.turn_id);
|
|
wait_for_event(&agent_run.thread, |event| {
|
|
matches!(event, EventMsg::TurnComplete(_))
|
|
})
|
|
.await;
|
|
|
|
let request = response_mock.single_request();
|
|
assert!(
|
|
request
|
|
.message_input_texts("user")
|
|
.iter()
|
|
.any(|text| text == "Use $example-agent to inspect the current changes.")
|
|
);
|
|
|
|
Ok(())
|
|
}
|