diff --git a/codex-rs/core/src/codex.rs b/codex-rs/core/src/codex.rs index 9ce2747823..1868f02c4d 100644 --- a/codex-rs/core/src/codex.rs +++ b/codex-rs/core/src/codex.rs @@ -131,9 +131,8 @@ use crate::skills::SkillInjections; use crate::skills::SkillMetadata; use crate::skills::SkillsManager; use crate::skills::build_skill_injections; -use crate::state::ActiveTurn; +use crate::state::AgentState; use crate::state::SessionServices; -use crate::state::SessionState; use crate::tasks::GhostSnapshotTask; use crate::tasks::ReviewTask; use crate::tasks::SessionTask; @@ -358,24 +357,6 @@ pub(crate) struct Session { /// /// The struct itself is stored in an `Arc`, so fields use `Mutex` to guard /// concurrent mutation rather than additional `Arc` layers. -pub(crate) struct AgentState { - pub(crate) agent_id: AgentId, - /// Session configuration + conversation history for this agent. - state: Mutex, - /// Active turn state is tracked per-agent (each agent can have its own task). - pub(crate) active_turn: Mutex>, -} - -impl AgentState { - fn new(agent_id: AgentId, session_configuration: SessionConfiguration) -> Self { - Self { - agent_id, - state: Mutex::new(SessionState::new(session_configuration)), - active_turn: Mutex::new(None), - } - } -} - /// The context needed for a single turn of the conversation. #[derive(Debug)] pub(crate) struct TurnContext { @@ -3059,7 +3040,6 @@ mod tests { use crate::tools::format_exec_output_str; use codex_protocol::models::FunctionCallOutputPayload; - use super::AgentState; use crate::protocol::CompactedItem; use crate::protocol::CreditsSnapshot; use crate::protocol::DEFAULT_AGENT_ID; @@ -3068,6 +3048,8 @@ mod tests { use crate::protocol::RateLimitWindow; use crate::protocol::ResumedHistory; use crate::protocol::RolloutLine; + use crate::state::AgentState; + use crate::state::SessionState; use crate::state::TaskKind; use crate::tasks::SessionTask; use crate::tasks::SessionTaskContext; diff --git a/codex-rs/core/src/state/agent.rs b/codex-rs/core/src/state/agent.rs new file mode 100644 index 0000000000..a37a5673d9 --- /dev/null +++ b/codex-rs/core/src/state/agent.rs @@ -0,0 +1,28 @@ +use tokio::sync::Mutex; + +use crate::codex::SessionConfiguration; +use crate::state::ActiveTurn; +use crate::state::SessionState; +use codex_protocol::protocol::AgentId; + +/// Per-agent mutable state shared across async tasks. +/// +/// The struct itself is stored in an `Arc`, so fields use `Mutex` to guard +/// concurrent mutation rather than additional `Arc` layers. +pub(crate) struct AgentState { + pub(crate) agent_id: AgentId, + /// Session configuration + conversation history for this agent. + pub(crate) state: Mutex, + /// Active turn state is tracked per-agent (each agent can have its own task). + pub(crate) active_turn: Mutex>, +} + +impl AgentState { + pub(crate) fn new(agent_id: AgentId, session_configuration: SessionConfiguration) -> Self { + Self { + agent_id, + state: Mutex::new(SessionState::new(session_configuration)), + active_turn: Mutex::new(None), + } + } +} diff --git a/codex-rs/core/src/state/mod.rs b/codex-rs/core/src/state/mod.rs index 642433a786..228b62034c 100644 --- a/codex-rs/core/src/state/mod.rs +++ b/codex-rs/core/src/state/mod.rs @@ -1,7 +1,9 @@ +mod agent; mod service; mod session; mod turn; +pub(crate) use agent::AgentState; pub(crate) use service::SessionServices; pub(crate) use session::SessionState; pub(crate) use turn::ActiveTurn;