Skip to content
Open
Show file tree
Hide file tree
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 Nov 24, 2025
0311f08
tui: add /agents list and @mentions
Grinsven Nov 24, 2025
168d94b
docs: document multi-agent system and config
Grinsven Nov 24, 2025
1dfb5a0
chore: add session notes and merge plan
Grinsven Nov 24, 2025
98d5839
tui: guard test-approval command for release builds
Grinsven Nov 24, 2025
f441814
fix: randomize agent tool call id and use dirs::home_dir
Grinsven Nov 24, 2025
75a64fd
fix: prevent path traversal via symlinks and support hyphens in agent…
Grinsven Nov 24, 2025
fccfaa6
agents: harden registry paths and mentions
Grinsven Nov 24, 2025
46ebd87
feat: integrate MCP tools into agent handler and update prompt config…
Grinsven Nov 24, 2025
c5e268f
fix: sub-agents inherit tools (preventing recursion)
Grinsven Nov 24, 2025
2e4e163
tests: add test for sub-agent tool inheritance
Grinsven Nov 24, 2025
90724d6
tests: add test for sub-agent tool inheritance
Grinsven Nov 24, 2025
d748631
fix: agent tool inheritance, canonicalize safety, and rand compilatio…
Grinsven Nov 24, 2025
41d9933
fix: ensure agent configuration validation checks for prompt or promp…
Grinsven Nov 24, 2025
440d167
remove reproduction test
Grinsven Nov 24, 2025
b690e21
fix: check for agents.toml symlink and enable parallel agent tool
Grinsven Nov 24, 2025
3d52a35
fix: persist agent events, refactor prompt loading, harden security
Grinsven Nov 24, 2025
652f075
fix: persist agent events, refactor prompt loading, harden security
Grinsven Nov 24, 2025
2d7fff8
fix: force Chat API for agents to avoid instructions error
Grinsven Nov 24, 2025
db8174f
fix: use system message workaround for agent instructions
Grinsven Nov 24, 2025
5a69741
fix: inject agent prompt as user message to pass validation
Grinsven Nov 24, 2025
13dc95e
fix: optimize agent prompt injection (remove redundant base instructi…
Grinsven Nov 24, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,13 @@ If you don’t have the tool:
let request = mock.single_request();
// assert using request.function_call_output(call_id) or request.json_body() or other helpers.
```

# Agent usage rules (ASCII-only)

- If the user asks for "two code reviewers" (or similar), run both @code_reviewer and @code_reviewer_b on the requested scope (latest diff/commits if unspecified), then merge findings ordered by severity with file:line.
- If the user asks for "two validators" (or similar), run both @validator and @validator_b on the requested scope, then merge findings ordered by severity with file:line.
- If the user asks for "a logic review", run @logic_reviewer.
- If the user asks for "a debugger", run @debugger.
- If the user asks for "research", run @researcher.
- Default scope when not provided: latest two commits in the current repo.
- Always cite file:line in findings and keep summaries concise.
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

It's a common convention to have a newline at the end of text files. Please add one here for consistency.

46 changes: 46 additions & 0 deletions MULTI_AGENT_IMPLEMENTATION.md
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.
21 changes: 21 additions & 0 deletions NEXT_SESSION_NOTES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Next Session Notes
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

This file appears to contain personal development notes and a PR draft. Such files are generally not committed to the repository. Please consider removing it from this pull request to keep the project history clean.


## 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.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ You can also use Codex with an API key, but this requires [additional setup](./d

### Model Context Protocol (MCP)

Codex can access MCP servers. To configure them, refer to the [config docs](./docs/config.md#mcp_servers).
Codex can access MCP servers. See the [config docs](./docs/config.md#mcp_servers) and the [advanced guide](./docs/advanced.md#model-context-protocol-mcp) for setup details; add an `mcp_servers` section to your `~/.codex/config.toml` to enable.

### Configuration

Expand Down Expand Up @@ -96,6 +96,10 @@ See the [Execpolicy quickstart](./docs/execpolicy.md) to set up rules that gover
- [**Advanced**](./docs/advanced.md)
- [Tracing / verbose logging](./docs/advanced.md#tracing--verbose-logging)
- [Model Context Protocol (MCP)](./docs/advanced.md#model-context-protocol-mcp)
- [**Multi-Agent System**](./docs/subagents.md)
- [Custom agent configuration](./docs/subagents.md#custom-agent-configuration)
- [Agent behavior](./docs/subagents.md#agent-behavior)
- [Best practices](./docs/subagents.md#best-practices)
- [**Zero data retention (ZDR)**](./docs/zdr.md)
- [**Contributing**](./docs/contributing.md)
- [**Install & build**](./docs/install.md)
Expand Down
39 changes: 39 additions & 0 deletions agent-merge-plan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Multi-agent merge plan (local fork)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

This file seems to be a local merge plan. It's good practice to exclude such temporary or personal planning documents from the repository's history. Please consider removing this file from the pull request.


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.
1 change: 1 addition & 0 deletions codex-rs/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading