-
Notifications
You must be signed in to change notification settings - Fork 2
Added: External directory permissions and cached rulesets #91
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
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d1c471b
Added: External directory permissions and cached rulesets
Sewer56 853426f
Changed: Speed up permission checks and Task runtime caching
Sewer56 f5c500d
Fixed: Address PR feedback on error handling and documentation
Sewer56 4448e5b
Changed: Return slice references from AgentRuntime accessors
Sewer56 6a0423a
Fixed: Enforce precondition in build_ruleset instead of silently coer…
Sewer56 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 |
|---|---|---|
|
|
@@ -42,3 +42,7 @@ rstest = "0.26" | |
| [[bench]] | ||
| name = "parser" | ||
| harness = false | ||
|
|
||
| [[bench]] | ||
| name = "runtime_task" | ||
| harness = false | ||
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,135 @@ | ||
| //! Benchmarks for [`AgentRuntime`] task-delegation cache lookups. | ||
| //! | ||
| //! Measures the cost of [`AgentRuntime::allowed_tools`], | ||
| //! [`AgentRuntime::summarize_callable_targets`], and | ||
| //! [`AgentRuntime::can_delegate_to`] across varying agent counts. | ||
|
|
||
| use ahash::AHashMap; | ||
| use core::hint::black_box; | ||
| use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput}; | ||
| use indexmap::IndexMap; | ||
| use llm_coding_tools_agents::{ | ||
| AgentCatalog, AgentConfig, AgentMode, AgentRuntimeBuilder, AgentToolSettings, PermissionRule, | ||
| }; | ||
| use llm_coding_tools_core::permissions::PermissionAction; | ||
| use llm_coding_tools_core::tool_metadata::{read as read_meta, task as task_meta}; | ||
|
|
||
| /// Build a minimal [`AgentConfig`] for benchmark fixtures. | ||
| /// | ||
| /// `permission` controls tool-access rules; all other fields are filled | ||
| /// with placeholder values suitable for performance measurement only. | ||
| fn build_agent( | ||
| name: &str, | ||
| mode: AgentMode, | ||
| permission: IndexMap<String, PermissionRule>, | ||
| ) -> AgentConfig { | ||
| AgentConfig { | ||
| name: name.into(), | ||
| mode, | ||
| description: format!("{name} description").into(), | ||
| model: None, | ||
| hidden: false, | ||
| temperature: None, | ||
| top_p: None, | ||
| permission, | ||
| options: AHashMap::new(), | ||
| tool_settings: AgentToolSettings::default(), | ||
| prompt: Default::default(), | ||
| } | ||
| } | ||
|
|
||
| /// Create a permission map that denies all tools by default, but allows | ||
| /// pattern-matched delegation to agents named `review-*` or `worker-*` | ||
| /// via the task tool, and blanket-allows the read tool. | ||
| fn patterned_task_permission() -> IndexMap<String, PermissionRule> { | ||
| let mut patterns = IndexMap::new(); | ||
| patterns.insert("*".to_string(), PermissionAction::Deny); | ||
| patterns.insert("review-*".to_string(), PermissionAction::Allow); | ||
| patterns.insert("worker-*".to_string(), PermissionAction::Allow); | ||
|
|
||
| IndexMap::from([ | ||
| (task_meta::NAME.into(), PermissionRule::Pattern(patterns)), | ||
| ( | ||
| read_meta::NAME.into(), | ||
| PermissionRule::Action(PermissionAction::Allow), | ||
| ), | ||
| ]) | ||
| } | ||
|
|
||
| /// Build an [`AgentRuntime`] with one `caller` primary agent and | ||
| /// `agent_count` subordinate agents. | ||
| /// | ||
| /// Subordinate names cycle through `review-NNN`, `worker-NNN`, and | ||
| /// `misc-NNN` prefixes. Every 11th subordinate is a primary-mode agent; | ||
| /// the rest are subagents. | ||
| fn build_runtime(agent_count: usize) -> llm_coding_tools_agents::AgentRuntime { | ||
| let mut agents = Vec::with_capacity(agent_count + 1); | ||
| agents.push(build_agent( | ||
| "caller", | ||
| AgentMode::Primary, | ||
| patterned_task_permission(), | ||
| )); | ||
|
|
||
| for idx in 0..agent_count { | ||
| let name = match idx % 3 { | ||
| 0 => format!("review-{idx:03}"), | ||
| 1 => format!("worker-{idx:03}"), | ||
| _ => format!("misc-{idx:03}"), | ||
| }; | ||
| let mode = if idx % 11 == 0 { | ||
| AgentMode::Primary | ||
| } else { | ||
| AgentMode::Subagent | ||
| }; | ||
| agents.push(build_agent(&name, mode, IndexMap::new())); | ||
| } | ||
|
|
||
| AgentRuntimeBuilder::new() | ||
| .catalog(AgentCatalog::from_entries(agents)) | ||
| .build() | ||
| } | ||
|
|
||
| /// Benchmark cached delegation queries against runtimes of 16, 64, and 256 agents. | ||
| /// | ||
| /// Measures four operations: | ||
| /// - **allowed_tools** – full tool-set resolution for the `caller` agent. | ||
| /// - **summaries** – callable-target summary strings for `caller`. | ||
| /// - **can_delegate_hit** – pattern-match hit (`caller` → `review-003`). | ||
| /// - **can_delegate_miss** – pattern-match miss (`caller` → `misc-002`). | ||
| fn bench_runtime_task_caches(c: &mut Criterion) { | ||
| let mut group = c.benchmark_group("runtime/task_caches"); | ||
|
|
||
| for agent_count in [16_usize, 64, 256] { | ||
| let runtime = build_runtime(agent_count); | ||
| group.throughput(Throughput::Elements(1)); | ||
|
|
||
| group.bench_with_input( | ||
| BenchmarkId::new("allowed_tools", agent_count), | ||
| &runtime, | ||
| |b, runtime| b.iter(|| black_box(runtime.allowed_tools("caller"))), | ||
| ); | ||
|
|
||
| group.bench_with_input( | ||
| BenchmarkId::new("summaries", agent_count), | ||
| &runtime, | ||
| |b, runtime| b.iter(|| black_box(runtime.summarize_callable_targets("caller"))), | ||
| ); | ||
|
|
||
| group.bench_with_input( | ||
| BenchmarkId::new("can_delegate_hit", agent_count), | ||
| &runtime, | ||
| |b, runtime| b.iter(|| black_box(runtime.can_delegate_to("caller", "review-003"))), | ||
| ); | ||
|
|
||
| group.bench_with_input( | ||
| BenchmarkId::new("can_delegate_miss", agent_count), | ||
| &runtime, | ||
| |b, runtime| b.iter(|| black_box(runtime.can_delegate_to("caller", "misc-002"))), | ||
| ); | ||
| } | ||
|
|
||
| group.finish(); | ||
| } | ||
|
|
||
| criterion_group!(benches, bench_runtime_task_caches); | ||
| criterion_main!(benches); | ||
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
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.
Uh oh!
There was an error while loading. Please reload this page.