-
Notifications
You must be signed in to change notification settings - Fork 7.2k
Add hierarchical agent prompt #8996
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
Merged
+123
−29
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5e9bebc
ha
pakrym-oai be37f56
project_doc: inline hierarchical agents message and simplify builder
pakrym-oai 5040a29
core: move hierarchical agents message to markdown file
pakrym-oai 79f8888
core: remove unused prompt_instructions module
pakrym-oai 68d53db
context_manager: use model base_instructions for token estimation
pakrym-oai bcd8f41
core: remove unused prompt_instructions module from exports
pakrym-oai 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| Files called AGENTS.md commonly appear in many places inside a container - at "/", in "~", deep within git repositories, or in any other directory; their location is not limited to version-controlled folders. | ||
|
|
||
| Their purpose is to pass along human guidance to you, the agent. Such guidance can include coding standards, explanations of the project layout, steps for building or testing, and even wording that must accompany a GitHub pull-request description produced by the agent; all of it is to be followed. | ||
|
|
||
| Each AGENTS.md governs the entire directory that contains it and every child directory beneath that point. Whenever you change a file, you have to comply with every AGENTS.md whose scope covers that file. Naming conventions, stylistic rules and similar directives are restricted to the code that falls inside that scope unless the document explicitly states otherwise. | ||
|
|
||
| When two AGENTS.md files disagree, the one located deeper in the directory structure overrides the higher-level file, while instructions given directly in the prompt by the system, developer, or user outrank any AGENTS.md content. |
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
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,71 @@ | ||
| use codex_core::features::Feature; | ||
| use core_test_support::load_sse_fixture_with_id; | ||
| use core_test_support::responses::mount_sse_once; | ||
| use core_test_support::responses::start_mock_server; | ||
| use core_test_support::test_codex::test_codex; | ||
|
|
||
| const HIERARCHICAL_AGENTS_SNIPPET: &str = | ||
| "Files called AGENTS.md commonly appear in many places inside a container"; | ||
|
|
||
| fn sse_completed(id: &str) -> String { | ||
| load_sse_fixture_with_id("../fixtures/completed_template.json", id) | ||
| } | ||
|
|
||
| #[tokio::test(flavor = "multi_thread", worker_threads = 2)] | ||
| async fn hierarchical_agents_appends_to_project_doc_in_user_instructions() { | ||
| let server = start_mock_server().await; | ||
| let resp_mock = mount_sse_once(&server, sse_completed("resp1")).await; | ||
|
|
||
| let mut builder = test_codex().with_config(|config| { | ||
| config.features.enable(Feature::HierarchicalAgents); | ||
| std::fs::write(config.cwd.join("AGENTS.md"), "be nice").expect("write AGENTS.md"); | ||
| }); | ||
| let test = builder.build(&server).await.expect("build test codex"); | ||
|
|
||
| test.submit_turn("hello").await.expect("submit turn"); | ||
|
|
||
| let request = resp_mock.single_request(); | ||
| let user_messages = request.message_input_texts("user"); | ||
| let instructions = user_messages | ||
| .iter() | ||
| .find(|text| text.starts_with("# AGENTS.md instructions for ")) | ||
| .expect("instructions message"); | ||
| assert!( | ||
| instructions.contains("be nice"), | ||
| "expected AGENTS.md text included: {instructions}" | ||
| ); | ||
| let snippet_pos = instructions | ||
| .find(HIERARCHICAL_AGENTS_SNIPPET) | ||
| .expect("expected hierarchical agents snippet"); | ||
| let base_pos = instructions | ||
| .find("be nice") | ||
| .expect("expected AGENTS.md text"); | ||
| assert!( | ||
| snippet_pos > base_pos, | ||
| "expected hierarchical agents message appended after base instructions: {instructions}" | ||
| ); | ||
| } | ||
|
|
||
| #[tokio::test(flavor = "multi_thread", worker_threads = 2)] | ||
| async fn hierarchical_agents_emits_when_no_project_doc() { | ||
| let server = start_mock_server().await; | ||
| let resp_mock = mount_sse_once(&server, sse_completed("resp1")).await; | ||
|
|
||
| let mut builder = test_codex().with_config(|config| { | ||
| config.features.enable(Feature::HierarchicalAgents); | ||
| }); | ||
| let test = builder.build(&server).await.expect("build test codex"); | ||
|
|
||
| test.submit_turn("hello").await.expect("submit turn"); | ||
|
|
||
| let request = resp_mock.single_request(); | ||
| let user_messages = request.message_input_texts("user"); | ||
| let instructions = user_messages | ||
| .iter() | ||
| .find(|text| text.starts_with("# AGENTS.md instructions for ")) | ||
| .expect("instructions message"); | ||
| assert!( | ||
| instructions.contains(HIERARCHICAL_AGENTS_SNIPPET), | ||
| "expected hierarchical agents message appended: {instructions}" | ||
| ); | ||
| } |
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 |
|---|---|---|
| @@ -1,3 +1,7 @@ | ||
| # AGENTS.md | ||
|
|
||
| For information about AGENTS.md, see [this documentation](https://developers.openai.com/codex/guides/agents-md). | ||
|
|
||
| ## Hierarchical agents message | ||
|
|
||
| When the `hierarchical_agents` feature flag is enabled (via `[features]` in `config.toml`), Codex appends additional guidance about AGENTS.md scope and precedence to the user instructions message and emits that message even when no AGENTS.md is present. |
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.
why so big of a change for appending instructions?
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.
simplify all various places we concat things, just one function that builds the final output./