forked from openai/codex
-
Notifications
You must be signed in to change notification settings - Fork 0
Add multi-agent tool support and docs #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Grinsven
wants to merge
22
commits into
main
Choose a base branch
from
agents-multi-final
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
b262f5c
core: add agent tool support
Grinsven 0311f08
tui: add /agents list and @mentions
Grinsven 168d94b
docs: document multi-agent system and config
Grinsven 1dfb5a0
chore: add session notes and merge plan
Grinsven 98d5839
tui: guard test-approval command for release builds
Grinsven f441814
fix: randomize agent tool call id and use dirs::home_dir
Grinsven 75a64fd
fix: prevent path traversal via symlinks and support hyphens in agent…
Grinsven fccfaa6
agents: harden registry paths and mentions
Grinsven 46ebd87
feat: integrate MCP tools into agent handler and update prompt config…
Grinsven c5e268f
fix: sub-agents inherit tools (preventing recursion)
Grinsven 2e4e163
tests: add test for sub-agent tool inheritance
Grinsven 90724d6
tests: add test for sub-agent tool inheritance
Grinsven d748631
fix: agent tool inheritance, canonicalize safety, and rand compilatio…
Grinsven 41d9933
fix: ensure agent configuration validation checks for prompt or promp…
Grinsven 440d167
remove reproduction test
Grinsven b690e21
fix: check for agents.toml symlink and enable parallel agent tool
Grinsven 3d52a35
fix: persist agent events, refactor prompt loading, harden security
Grinsven 652f075
fix: persist agent events, refactor prompt loading, harden security
Grinsven 2d7fff8
fix: force Chat API for agents to avoid instructions error
Grinsven db8174f
fix: use system message workaround for agent instructions
Grinsven 5a69741
fix: inject agent prompt as user message to pass validation
Grinsven 13dc95e
fix: optimize agent prompt injection (remove redundant base instructi…
Grinsven File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| # Multi-Agent Feature Implementation Notes | ||
|
|
||
| ## Completed Tasks (as of 2025-11-24) | ||
|
|
||
| ### Core Implementation | ||
| - [x] **Agent Registry**: Implemented in `codex-rs/core/src/agent.rs` to load agent configurations from `~/.codex/agents.toml`. | ||
| - Added security validation to prevent loading prompts from outside the allowed directory (`validate_prompt_path`). | ||
| - Added symlink protection for the configuration file itself. | ||
| - Implemented nested prompt loading refactor for readability. | ||
| - [x] **Agent Handler**: Implemented `AgentHandler` in `codex-rs/core/src/tools/handlers/agent.rs` to execute agent tasks. | ||
| - Uses the `agent` tool to invoke sub-agents. | ||
| - **Tool Inheritance**: Sub-agents inherit tools from the parent session, but the `agent` tool itself is excluded to prevent recursion. | ||
| - **ID Randomization**: Uses `rand::thread_rng().r#gen()` to generate unique call IDs, fixing potential collision issues and deprecated usage. | ||
| - **Response Handling**: Streams agent output and reasoning deltas back to the session. | ||
| - [x] **Protocol Updates**: Added `AgentBegin`, `AgentProgress`, `AgentEnd`, and `ListAgentsResponse` events to `codex-rs/protocol/src/protocol.rs`. | ||
| - Updated `codex-rs/core/src/rollout/policy.rs` to persist `AgentBegin` and `AgentEnd` events for history playback. | ||
| - [x] **Tools Spec**: Registered the `agent` tool in `codex-rs/core/src/tools/spec.rs`. | ||
| - Enabled parallel execution support for the agent tool. | ||
|
|
||
| ### TUI Integration | ||
| - [x] **Slash Commands**: Added `/agents` command to list available agents (`codex-rs/tui/src/chatwidget.rs`, `slash_command.rs`). | ||
| - [x] **Mentions**: Implemented parsing for `@agent: task` syntax in `codex-rs/tui/src/agent_mention.rs`. | ||
| - Regex updated to support hyphens in agent names (e.g., `@code-reviewer`). | ||
| - Mentions are converted into `agent` tool calls before submission. | ||
| - [x] **Visual Feedback**: Added history cells for agent execution status (running, progress, done) in `codex-rs/tui/src/history_cell.rs`. | ||
|
|
||
| ### Documentation | ||
| - [x] **Guide**: Created `docs/subagents.md` detailing configuration, usage, and best practices. | ||
| - [x] **Examples**: Created `example-agents.toml` with sample agent configurations. | ||
| - [x] **Getting Started**: Updated `README.md` and `docs/getting-started.md` with quickstart instructions. | ||
| - [x] **AGENTS.md**: Added agent usage rules and ensured trailing newline compliance. | ||
|
|
||
| ### Testing | ||
| - [x] **Unit Tests**: Added tests for agent registry validation and mention parsing. | ||
| - [x] **Integration Tests**: Added `sub_agent_inherits_tools` test in `codex-rs/core/tests/suite/agent_tool.rs` to verify tool inheritance logic. | ||
| - [x] **Verification**: All tests passed in `codex-core` (459 tests) and `codex-tui` (490 tests). | ||
|
|
||
| ## Pending / Future Work | ||
| - [ ] **Runtime Error Investigation**: The error `{"detail":"Instructions are not valid"}` was observed when running agents against specific endpoints (likely GitHub Models/Azure). This is identified as a configuration mismatch (using `Responses` protocol with an endpoint that rejects `instructions`). Future work could auto-detect this or warn the user. | ||
| - [ ] **Test Coverage**: Add more robust integration tests for the TUI interactions if possible (currently manual verification). | ||
| - [ ] **Release**: Build and publish the updated `codex-cli` package. | ||
|
|
||
| ## Branch State | ||
| - **Branch**: `agents-multi-final` | ||
| - **Latest Commit**: `3d52a35cc` (fix: persist agent events, refactor prompt loading, harden security) | ||
| - **Sync Status**: Local workspace is synced with remote. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| # Next Session Notes | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| ## What was done | ||
| - Added agent tool support end-to-end: core handler/events, registry listing, TUI @mentions and `/agents`, docs + example config. | ||
| - Hardened agent prompt path validation and fatal init errors; refreshed plan file `agent-merge-plan.md` and new docs `docs/subagents.md`. | ||
| - Quick doc polish: added multi-agent quickstart to `docs/getting-started.md` and follow-ups section to `agent-merge-plan.md`. | ||
| - Formatting/linting: `just fmt`, `just fix -p codex-core`, `just fix -p codex-tui`. | ||
| - Tests: `cargo test -p codex-core --tests`, `cargo test -p codex-tui` (all passing). | ||
|
|
||
| ## What’s left / next session | ||
| - Packaging: stage/commit remaining changes (plan + notes, docs, code) and write PR description (scope, risks, tests run). | ||
| - Optional: run full workspace tests `cargo test --all-features` if time permits. | ||
|
|
||
| ## PR draft (copy/paste) | ||
| - Title: "Add multi-agent tool support and TUI mentions" | ||
| - Summary: | ||
| - Reintroduce agent protocol and tool handler; wire registry into core session flow. | ||
| - Add TUI `/agents` list and `@agent` mention handling with plan integration. | ||
| - Document multi-agent usage (`docs/subagents.md`, quickstart in getting-started, config snippet, example `agents.toml`). | ||
| - Risks: new tool path touching core session/tool dispatch; TUI input parsing for mentions. | ||
| - Tests: `cargo test -p codex-core --tests` and `cargo test -p codex-tui` (passing). Consider optional `cargo test --all-features` before upstream PR. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| # Multi-agent merge plan (local fork) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| Goal: keep current `main` core runtime, layer in multi-agent support from PR #3655 with minimal regression risk. | ||
|
|
||
| Status legend: ☐ not started · ⭕ in progress · ✅ done | ||
|
|
||
| ## Tasks | ||
|
|
||
| - ✅ Reset core to main for runtime files | ||
| - Restore `codex-rs/core/src/codex.rs` from `origin/main` | ||
| - Remove PR-only `codex-rs/core/src/codex/compact.rs` and `codex-rs/core/src/openai_tools.rs` | ||
| - ✅ Reintroduce agent protocol/events into core | ||
| - Wire agent events through event dispatch | ||
| - Add agent tool flag in existing tool builder (current main) | ||
| - Pass agent registry info to tool construction | ||
| - ✅ Implement minimal agent execution path | ||
| - Keep `core/src/agent.rs` registry loader | ||
| - Handle agent tool calls in `codex.rs` using current Session/TurnContext APIs | ||
| - Ensure safety/plan/turn_diff compatibility | ||
| - ✅ TUI integration | ||
| - Ensure `/agents` and @mention handling compile with new core events | ||
| - ✅ Docs/examples | ||
| - Verify `docs/subagents.md`, `example-agents.toml` references remain accurate | ||
| - ✅ Format & test | ||
| - `just fmt` | ||
| - `cargo test -p codex-core --tests --no-run` | ||
| - `cargo test -p codex-tui` (update snapshots if needed) | ||
|
|
||
| ## Notes | ||
|
|
||
| - Keep protocol agent structs already merged. | ||
| - Avoid reviving deleted legacy modules; adapt to current architecture instead. | ||
|
|
||
| ## Follow-ups | ||
|
|
||
| - ✅ Doc polish: align `docs/getting-started.md`, `docs/config.md`, and `docs/subagents.md` language; keep `example-agents.toml` consistent with tool names/fields. | ||
| - ✅ Final verification: quick pass over agent registry wiring and example config after doc tweaks. | ||
| - ☐ Packaging: stage/commit, write PR summary (scope, risks, test matrix). | ||
| - ☐ Optional: full sweep `cargo test --all-features` before opening upstream PR. | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a common convention to have a newline at the end of text files. Please add one here for consistency.