Skip to content

feat: use llm to select skill when no skill selected#2777

Open
ddu-aeron wants to merge 14 commits into
nearai:mainfrom
ddu-aeron:staging
Open

feat: use llm to select skill when no skill selected#2777
ddu-aeron wants to merge 14 commits into
nearai:mainfrom
ddu-aeron:staging

Conversation

@ddu-aeron
Copy link
Copy Markdown

@ddu-aeron ddu-aeron commented Apr 21, 2026

we are trying to use skills from clawhub and it do not have activation keyworkds, this pr will try to select these skills using llm as a fallback

Summary

  • add LLM skill-selection fallback when no skills selected
  • Add token cost tracking for the LLM skill-selection fallback

Change Type

  • Bug fix
  • New feature
  • Refactor
  • Documentation
  • CI/Infrastructure
  • Security
  • Dependencies

Linked Issue

Validation

  • cargo fmt --all -- --check
  • cargo clippy --all --benches --tests --examples --all-features -- -D warnings
  • cargo build
  • Relevant tests pass:
  • cargo test --features integration if database-backed or integration behavior changed
  • Manual testing: tested with a skill without activation and it was selected
  • If a coding agent was used and supports it, review-pr or pr-shepherd --fix was run before requesting review

Security Impact

Database Impact

Blast Radius

Touches src/llm/reasoning.rs (return type of select_skill_names_with_llm),
src/agent/agent_loop.rs (LLM fallback candidate filter + cost recording),
and test fixtures in src/agent/dispatcher.rs. No change to the happy path
for explicit or deterministic skill selection.

Rollback Plan

Revert the three files changed in this PR. No schema or config changes involved.

Review Follow-Through

The fallback_candidates filter now excludes any skill that has at least one
keyword, pattern, or tag. If a skill is intended to be description-only (no
activation criteria), it will still reach the LLM fallback. Reviewers should
confirm this is the desired boundary.


Review track:

  - use llm as fallback for skill selector
  - only filter skills that do not have keywords and pattern
@github-actions github-actions Bot added size: L 200-499 changed lines scope: agent Agent core (agent loop, router, scheduler) scope: llm LLM integration scope: docs Documentation risk: medium Business logic, config, or moderate-risk modules contributor: new First-time contributor and removed size: L 200-499 changed lines labels Apr 21, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces an LLM-based fallback mechanism for skill selection, triggered when explicit mentions or deterministic keyword matching do not yield results. It includes logic for candidate filtering, context token budget management, and cost tracking for the fallback LLM call. The dispatcher was also updated to ensure correct message context is used during approval-resume flows. Review feedback suggests optimizing the implementation by using a cheaper LLM model for the selection task and utilizing standard JSON serialization instead of pretty-printing to reduce token overhead.

Comment thread src/agent/agent_loop.rs Outdated
Comment thread src/llm/reasoning.rs Outdated
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@github-actions github-actions Bot added the size: L 200-499 changed lines label Apr 21, 2026
…mpts

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@serrrfirat
Copy link
Copy Markdown
Collaborator

Nice improvement for the v1 path. One thing to call out: this is still v1-only, since engine v2 does skill selection in crates/ironclaw_engine/orchestrator/default.py (via select_skills(...) / __list_skills__()), not in src/agent/*.

If we want parity, we should mirror the same behavior in v2 as a follow-up: keep explicit /skill-name + deterministic keyword/pattern selection as the primary path, and only fall back to an LLM-based selector when that path returns no skills. I’d also keep the same guardrail from this PR and only offer the LLM skills that have no positive activation metadata, so the LLM doesn’t second-guess deterministic exclusions.

Otherwise we’ll have different skill-selection behavior between v1 and v2 during the migration.

@ddu-aeron
Copy link
Copy Markdown
Author

Nice improvement for the v1 path. One thing to call out: this is still v1-only, since engine v2 does skill selection in crates/ironclaw_engine/orchestrator/default.py (via select_skills(...) / __list_skills__()), not in src/agent/*.

If we want parity, we should mirror the same behavior in v2 as a follow-up: keep explicit /skill-name + deterministic keyword/pattern selection as the primary path, and only fall back to an LLM-based selector when that path returns no skills. I’d also keep the same guardrail from this PR and only offer the LLM skills that have no positive activation metadata, so the LLM doesn’t second-guess deterministic exclusions.

Otherwise we’ll have different skill-selection behavior between v1 and v2 during the migration.

You are correct! we should keep the same logic in v2 engine. but im not familiar with python and still dont know how to test v2 engine.

i will dig into the code base with help of AI. and try to impl it. it would be great if some would help!

Comment thread src/agent/agent_loop.rs
Comment thread src/agent/agent_loop.rs
Comment thread src/llm/reasoning.rs
* fix: disable canara issues creation

* ci: re-trigger regression-test-check after adding skip-regression-check label
@henrypark133 henrypark133 changed the base branch from staging to main May 1, 2026 06:15
@github-actions github-actions Bot added size: XL 500+ changed lines and removed size: L 200-499 changed lines labels May 1, 2026
@ddu-aeron
Copy link
Copy Markdown
Author

@serrrfirat v2 engine part is finished and tested manually, please review the change

@github-actions github-actions Bot added scope: channel/web Web gateway channel scope: ci CI/CD workflows labels May 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor: new First-time contributor risk: medium Business logic, config, or moderate-risk modules scope: agent Agent core (agent loop, router, scheduler) scope: channel/web Web gateway channel scope: ci CI/CD workflows scope: docs Documentation scope: llm LLM integration size: XL 500+ changed lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants