mirror of
https://github.com/openai/codex.git
synced 2026-11-24 07:20:27 +00:00
Share model-visible tool specs across prompts (#37807)
## Why Building a prompt cloned every model-visible `ToolSpec`, even though the tool set is immutable for the lifetime of its router. ## What changed - Store model-visible tool specs as an `Arc<[ToolSpec]>` in `ToolRouter` and `Prompt` so prompt construction only clones the shared pointer. - Keep separately built routers on distinct shared slices so refreshed tool sets remain independent. ## Testing Extend router tests to verify allocation sharing within a router, allocation separation across rebuilt routers, and the existing deferred-tool filtering. GitOrigin-RevId: 1e04cd7c4d1b3fa0b494c5c51670232d38ba8ebb
This commit is contained in:
1 parent
c8e6e8555c
commit
beeba1d2fc
4 files changed
+16
-8
No files matched your search
@@ -471,9 +471,11 @@ async fn specs_filter_deferred_dynamic_tools() -> anyhow::Result<()> {
|
||||
Vec::new(),
|
||||
&dynamic_tools,
|
||||
);
|
||||
let visible_specs = router.model_visible_specs();
|
||||
|
||||
assert!(Arc::ptr_eq(&visible_specs, &router.model_visible_specs()));
|
||||
assert_eq!(
|
||||
namespace_function_names(&router.model_visible_specs(), "codex_app"),
|
||||
namespace_function_names(&visible_specs, "codex_app"),
|
||||
vec![visible_tool.to_string()]
|
||||
);
|
||||
assert_eq!(
|
||||
@@ -481,6 +483,11 @@ async fn specs_filter_deferred_dynamic_tools() -> anyhow::Result<()> {
|
||||
BTreeMap::from([("codex_app".to_string(), "Codex app tools.".to_string())])
|
||||
);
|
||||
|
||||
let updated_router = test_tool_router(step_context.as_ref(), Vec::new(), Vec::new(), &[]);
|
||||
let updated_specs = updated_router.model_visible_specs();
|
||||
assert!(!Arc::ptr_eq(&visible_specs, &updated_specs));
|
||||
assert!(namespace_function_names(&updated_specs, "codex_app").is_empty());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user