feat: implement (multi) subagent orchestration system#3655
feat: implement (multi) subagent orchestration system#3655metaphorics wants to merge 28 commits intoopenai:mainfrom
Conversation
- Add agent.rs module with AgentRegistry for managing custom agents - Support loading agent configurations from ~/.codex/agents.toml - Enable agent-specific system prompts with file-based loading - Add comprehensive subagents documentation with usage examples - Include example-agents.toml with 10 specialized agent templates - Update README with multi-agent system documentation links - Integrate agent system into core Codex architecture - Support inheritance of tools/permissions from workspace context - Prevent recursive agent spawning for system stability The multi-agent system allows users to define specialized AI agents with custom system prompts for tasks like code review, testing, refactoring, security auditing, and performance analysis.
|
All contributors have signed the CLA ✍️ ✅ |
|
I have read the CLA Document and I hereby sign the CLA |
|
@codex review |
|
You have reached your rate limits for code reviews, please try again later |
|
@codex review |
There was a problem hiding this comment.
Codex Review: Here are some suggestions.
About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you open a pull request for review, mark a draft as ready, or comment "@codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex fix this CI failure" or "@codex address that feedback".
Added a new function `validate_prompt_path` in the `AgentRegistry` to ensure that prompt file paths do not escape allowed directories, preventing potential path traversal attacks. This function checks if the provided path is within the user's home directory or the base directory, returning an error if it is not. Updated the agent loading logic to utilize this validation, enhancing security during agent initialization.
Updated the agent context creation to improve clarity and functionality. The task extraction logic from the agent prompt has been refined to ensure that the user's task is correctly identified and handled. This change includes better error handling for cases where no task is found, and improved logging for agent execution. Additionally, comments have been updated to reflect the new structure and intent of the code.
|
You have reached your rate limits for code reviews, please try again later |
|
@codex review |
There was a problem hiding this comment.
Codex Review: Here are some suggestions.
About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you open a pull request for review, mark a draft as ready, or comment "@codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex fix this CI failure" or "@codex address that feedback".
Updated the agent ID generation logic to safely truncate the call ID, ensuring unique identifiers are created without risk of overflow. Additionally, introduced an `AgentContextGuard` struct to manage the agent context flag more effectively, ensuring it is reset appropriately after use. This change enhances clarity and reliability in agent execution tracking.
Enhanced the `AgentContextGuard` struct to ensure the agent context flag is reset appropriately after use, improving reliability in agent execution tracking. Updated comments for clarity and added logging to indicate when the agent context is marked and unmarked, ensuring better traceability during agent operations.
|
@codex review |
There was a problem hiding this comment.
Codex Review: Here are some suggestions.
About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you open a pull request for review, mark a draft as ready, or comment "@codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex fix this CI failure" or "@codex address that feedback".
|
Hello! Just a bump. Super excited to get this integrated. Amazing work @cognitive-glitch. |
|
every day I came here hoping this would have been merged into a new release! Just a question: For example, the possibility of agent A having instructions to call agents B, C, D... which may or may not also have instructions to call other agents. In some research cases where I work, I'd like to invoke a specific agent with some instructions to search for code files that specify exactly file:line, without polluting the context window of the agent that build the research report. |
|
I have nothing productive to add, just wanted to say thank you for doing the Lord's work |
|
Can add agent popup to hint when specify agent? |
|
can't wait for the subagent feature! |
|
What's going on? |
|
Does has any update on this? @cognitive-glitch does you still in progress? Can I fork your branch and make new PR? |
Praying that OP didn't vanish entirely 🙏 |
|
Any news on this? |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
| ResponseItem::CustomToolCall { name, call_id, .. } if name == "agent" => { | ||
| // Collect agent calls for parallel execution | ||
| pending_agent_calls.push(PendingToolCall { | ||
| item: item.clone(), | ||
| call_id: call_id.clone(), | ||
| name: name.clone(), | ||
| arguments: None, | ||
| }); | ||
| } | ||
| ResponseItem::CustomToolCall { .. } => { | ||
| // Process non-agent custom tool calls immediately in order | ||
| let response = handle_response_item( | ||
| sess, | ||
| turn_context, | ||
| turn_diff_tracker, | ||
| sub_id, | ||
| item.clone(), | ||
| ) | ||
| .await?; | ||
| if let Some(resp) = response.clone() { | ||
| output.push(resp); | ||
| } | ||
| processed_items.push(ProcessedResponseItem { | ||
| item: item.clone(), | ||
| response, | ||
| }); | ||
| } | ||
| _ => { | ||
| // Process non-tool items immediately in order | ||
| let response = handle_response_item( | ||
| sess, | ||
| turn_context, | ||
| turn_diff_tracker, | ||
| sub_id, | ||
| item.clone(), | ||
| ) | ||
| .await?; | ||
| if let Some(resp) = response.clone() { | ||
| output.push(resp); | ||
| } | ||
| processed_items.push(ProcessedResponseItem { item, response }); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Process pending agent calls in parallel if any were collected | ||
| if !pending_agent_calls.is_empty() { | ||
| // Handle agent calls with TRUE PARALLEL EXECUTION | ||
| // All agents run concurrently at the same time, not sequentially | ||
| // This provides maximum performance for multi-agent orchestration | ||
|
|
||
| // Notify UI about parallel agent execution starting | ||
| if pending_agent_calls.len() > 1 { | ||
| let event = Event { | ||
| id: sub_id.to_string(), | ||
| msg: EventMsg::BackgroundEvent(BackgroundEventEvent { | ||
| message: format!( | ||
| "🚀 Starting {} agents in PARALLEL...", | ||
| pending_agent_calls.len() | ||
| ), | ||
| }), | ||
| }; | ||
| sess.send_event(event).await; | ||
| } | ||
|
|
||
| let agent_call_params: Vec<_> = pending_agent_calls | ||
| .iter() | ||
| .map(|call| { | ||
| ( | ||
| call.call_id.clone(), | ||
| call.arguments.clone().unwrap_or_default(), | ||
| sub_id.to_string(), |
There was a problem hiding this comment.
Preserve agent tool input for custom tool calls
When collecting pending agent calls, the ResponseItem::CustomToolCall branch pushes a PendingToolCall with arguments: None. Later, the executor builds agent_call_params using call.arguments.clone().unwrap_or_default() and then attempts to parse the resulting string into AgentToolArgs. For any agent invocation that arrives as a custom tool call, this produces an empty string, causing execute_agents_concurrent_safe to return a "Failed to parse agent arguments" error and the agent never runs. Custom tool calls (e.g., from MCP servers or non-OpenAI providers) therefore cannot use the new agent system at all. Store the call’s input payload in PendingToolCall so that the JSON is available during execution.
Useful? React with 👍 / 👎.
|
any progress? |
|
Suspense is killing me! |
|
I wonder if it would be ok to start working on a separate implementation of the multi-agent setup in a separate PR, or is that considered bad practice? |
Do it. This one seems like its dead in the water. |
|
@gpeal will there be an official solution from OpenAI or should the community come up with a solution? |
|
I would say it is better to continue this PR instead of reinventing the wheel |
|
Why aren't maintainers responding to this? Can it be accepted? If not, why? |
They ran out of f's to give about what we want. They have their internal agenda which they are following. This project is as Open Source as OpenAI is "Open" |
|
Ask Sam to hire more devs please! |
Or to divert 1% of their GPUs into Agents that solve Issues and PRs |
|
Hey guys! save us plzzz @ccy-oai @nornagon-openai @jif-oai @dedrisian-oai @pakrym-oai @rakesh-oai |
|
I made my own implementation of multi-agent Codex capabilities—if anyone’s interested: #5190 |
|
Thanks for the contribution, and apologies for the slow response. We've received many PRs, and we don't have the bandwidth on the codex team to review all of them. We've updated our contribution guidelines to clarify that we're currently accepting contributions for bugs and security fixes, but we're not generally accepting new features at this time. We need to make sure that all new features compose well with both existing and upcoming features and fit into our roadmap. If you would like to propose a new feature, please file or upvote an enhancement request in the issue tracker. We will generally prioritize new features based on community feedback. |
The multi-agent system allows users to define specialized AI agents
with custom system prompts for tasks like code review, testing,
refactoring, security auditing, and performance analysis.
Resolving #2604