Skip to content

feat: implement (multi) subagent orchestration system#3655

Closed
metaphorics wants to merge 28 commits intoopenai:mainfrom
metaphorics:main
Closed

feat: implement (multi) subagent orchestration system#3655
metaphorics wants to merge 28 commits intoopenai:mainfrom
metaphorics:main

Conversation

@metaphorics
Copy link
Copy Markdown

@metaphorics metaphorics commented Sep 15, 2025

  • 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.


Resolving #2604

- 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.
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Sep 15, 2025

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@metaphorics metaphorics changed the title feat: implement multi-(sub)agent orchestration system #2604 feat: implement (multi) subagent orchestration system #2604 Sep 15, 2025
@metaphorics
Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

github-actions Bot added a commit that referenced this pull request Sep 15, 2025
@metaphorics metaphorics mentioned this pull request Sep 15, 2025
13 tasks
@metaphorics
Copy link
Copy Markdown
Author

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown
Contributor

You have reached your rate limits for code reviews, please try again later

@MiguelRipoll23
Copy link
Copy Markdown

@codex review

Copy link
Copy Markdown
Contributor

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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".

Comment thread codex-rs/core/src/codex.rs Outdated
Comment thread codex-rs/core/src/openai_tools.rs Outdated
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.
@chatgpt-codex-connector
Copy link
Copy Markdown
Contributor

You have reached your rate limits for code reviews, please try again later

@metaphorics
Copy link
Copy Markdown
Author

@codex review

Copy link
Copy Markdown
Contributor

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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".

Comment thread codex-rs/core/src/codex.rs Outdated
Comment thread codex-rs/core/src/openai_tools.rs Outdated
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.
@metaphorics
Copy link
Copy Markdown
Author

@codex review

Copy link
Copy Markdown
Contributor

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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".

Comment thread codex-rs/core/src/codex.rs Outdated
@metaphorics metaphorics changed the title feat: implement (multi) subagent orchestration system #2604 feat: implement (multi) subagent orchestration system Sep 15, 2025
@taylor-shift
Copy link
Copy Markdown

Hello! Just a bump.

Super excited to get this integrated. Amazing work @cognitive-glitch.

@GFBarbosa
Copy link
Copy Markdown

GFBarbosa commented Sep 20, 2025

every day I came here hoping this would have been merged into a new release!

Just a question:
Would it be possible to work with a higher degree of recursion on this?

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.

@Git-on-my-level
Copy link
Copy Markdown

I have nothing productive to add, just wanted to say thank you for doing the Lord's work

@lavpicap
Copy link
Copy Markdown

Can add agent popup to hint when specify agent?

@koksing456
Copy link
Copy Markdown

can't wait for the subagent feature!

@vellengs
Copy link
Copy Markdown

What's going on?

@lavpicap
Copy link
Copy Markdown

lavpicap commented Oct 3, 2025

Does has any update on this? @cognitive-glitch does you still in progress? Can I fork your branch and make new PR?

@John0x
Copy link
Copy Markdown

John0x commented Oct 4, 2025

When the world needed him most he vanished

Praying that OP didn't vanish entirely 🙏
This would be such a huge addition to Codex. Maybe the Team can lend a hand to advance this effort? @tibo-openai

@tgvivo-opinaia
Copy link
Copy Markdown

Any news on this?

@alexx-ftw
Copy link
Copy Markdown

@codex review

Copy link
Copy Markdown
Contributor

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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 👍.

Comment on lines +2333 to +2404
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(),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

@fallonou1999
Copy link
Copy Markdown

any progress?

@matthewharwood
Copy link
Copy Markdown

Suspense is killing me!

@MasterMind7777777
Copy link
Copy Markdown
Contributor

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?

@taylor-shift
Copy link
Copy Markdown

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.

@mxmalykhin
Copy link
Copy Markdown

@gpeal will there be an official solution from OpenAI or should the community come up with a solution?

@alexx-ftw
Copy link
Copy Markdown

I would say it is better to continue this PR instead of reinventing the wheel

@adbl
Copy link
Copy Markdown

adbl commented Oct 13, 2025

Why aren't maintainers responding to this? Can it be accepted? If not, why?

@alexx-ftw
Copy link
Copy Markdown

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"

@ChrisWiles
Copy link
Copy Markdown

Ask Sam to hire more devs please!

@alexx-ftw
Copy link
Copy Markdown

Ask Sam to hire more devs please!

Or to divert 1% of their GPUs into Agents that solve Issues and PRs

@GFBarbosa
Copy link
Copy Markdown

Hey guys! save us plzzz

@ccy-oai @nornagon-openai @jif-oai @dedrisian-oai @pakrym-oai @rakesh-oai

@MasterMind7777777
Copy link
Copy Markdown
Contributor

I made my own implementation of multi-agent Codex capabilities—if anyone’s interested: #5190

@etraut-openai
Copy link
Copy Markdown
Collaborator

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.

@github-actions github-actions Bot locked and limited conversation to collaborators Oct 30, 2025
@openai openai unlocked this conversation Oct 30, 2025
youta7 added a commit to youta7/ta-codex that referenced this pull request Nov 10, 2025
swordfish444 pushed a commit to swordfish444/codex that referenced this pull request Feb 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.