feat(agents): add tool_agent_class parameter to AgentFactory and create_executor #74
Merged
hurui200320
merged 1 commits from 2026-07-08 09:44:17 +00:00
feature/m1-tool-agent-class-injection into master
No Reviewers
Labels
Clear labels
auto/blocked-by-deps
auto/ci-timeout
auto/claimed-implementer
auto/claimed-merge
auto/claimed-reviewer
auto/driver-down
auto/invariant-violation
auto/last-attempt-tier-0
auto/last-attempt-tier-1
auto/last-attempt-tier-2
auto/last-attempt-tier-min
Automation Tracking
auto/needs-conflict-resolution
auto/needs-implementer
auto/postmortem
auto/ready-to-merge
auto/restart-throttled
auto/revert
auto/sentinel
auto/stale-inactivity
auto/unstable
Blocked
Needs Feedback
Signed-off: Owner
Signed-off: Scrum Master
Signed-off: Tech Lead
Spike
PR blocked by an open issue dependency. Operator must close the dep (or remove the dependency link) before the merge driver can act. Auto-cleared by merge_drive when no open deps remain.
Most recent merge cycle hit CI timeout. Driver excludes this PR while last merge_cycle row is < 30 min old; label persists thereafter as visible history.
Currently being processed by an implementer worker.
Currently being processed by the merge driver.
Currently being processed by a reviewer worker.
Merge driver heartbeat stale; pipeline halted. Closed automatically on next clean tick.
Detected master commit violating the strict merge invariant. Tracked as an issue (not a PR label); kept here for label completeness.
In-cycle escalation: most recent attempt ran at the Tier 0 slot (`tier-0`). Slot's model defined in .opencode/models/tiers.yaml.
In-cycle escalation: most recent attempt ran at the Tier 1 slot (`tier-1`). Slot's model defined in .opencode/models/tiers.yaml.
In-cycle escalation: most recent attempt ran at the Tier 2 slot (`tier-2`). Slot's model defined in .opencode/models/tiers.yaml. Gated behind IMPLEMENTER_ESCALATION_TIER2_ENABLED.
In-cycle escalation: most recent attempt ran at the Tier -1 slot (`tier-min`). Slot's model defined in .opencode/models/tiers.yaml. Suffix is ``-min`` (not ``--1``) so the Forgejo UI reads naturally.
Tracking issues used by the AI Automation system for agents to communicate and report.
Rebase conflict needs LLM conflict-resolver.
Failing CI needs implementer attention.
Documenting a driver incident or rollback.
Reviewer has APPROVED this PR and no later REQUEST_CHANGES is outstanding. The merge driver requires this label to even consider a PR for merging. Set by the reviewer worker on APPROVE; cleared on REQUEST_CHANGES.
Train repeatedly lost master-tempo races. Driver excludes via merge_cycle until cooldown elapses; label persists as visible history.
Revert PR backing out an invariant violation. Fast-tracked through the merge driver.
Sentinel PR duplicated from upstream into a personal fork by tools/duplicate_prs_to_fork.py for pipeline testing. Lives only in the fork; the canonical pipeline never sees it.
No implementer activity for N days. Flagged for human review. Auto-cleared on next push to head branch.
Repeatedly fails on current master (>= 3 ci-fail-on-rebased-sha releases in 12 h). Excluded from driver until human triage.
A ticket in a blocked state and unable to complete until some other task is completed first.
Bounty
$100
A bounty of $100 for any open-source contributor who provides a MR that solves this issue
Bounty
$1000
A bounty of $1000 for any open-source contributor who provides a MR that solves this issue
Bounty
$10000
A bounty of $10000 for any open-source contributor who provides a MR that solves this issue
Bounty
$20
A bounty of $20 for any open-source contributor who provides a MR that solves this issue
Bounty
$2000
A bounty of $2000 for any open-source contributor who provides a MR that solves this issue
Bounty
$250
A bounty of $250 for any open-source contributor who provides a MR that solves this issue
Bounty
$50
A bounty of $50 for any open-source contributor who provides a MR that solves this issue
Bounty
$500
A bounty of $500 for any open-source contributor who provides a MR that solves this issue
Bounty
$5000
A bounty of $5000 for any open-source contributor who provides a MR that solves this issue
Bounty
$750
A bounty of $750 for any open-source contributor who provides a MR that solves this issue
MoSCoW
Could have
Could have feature in order to satisfy the epic/legendary.
MoSCoW
Must have
Must have feature in order to satisfy the epic/legendary.
MoSCoW
Should have
Should have feature in order to satisfy the epic/legendary.
There are questions in the ticket that can not be completed until the project owner provides clarity.
Points
1
1 man-hours worth of work for an expert with no learning curve.
Points
13
13 man-hours worth of work for an expert with no learning curve.
Points
2
2 man-hours worth of work for an expert with no learning curve.
Points
21
21 man-hours worth of work for an expert with no learning curve.
Points
3
3 man-hours worth of work for an expert with no learning curve.
Points
34
34 man-hours worth of work for an expert with no learning curve.
Points
5
5 man-hours worth of work for an expert with no learning curve.
Points
55
55 man-hours worth of work for an expert with no learning curve.
Points
8
8 man-hours worth of work for an expert with no learning curve.
Points
88
88 man-hours worth of work for an expert with no learning curve.
Priority
Backlog
This ticket has backlogged priority and is not to be worked on yet
Priority
CI Blocker
Critical priority issue that blocks CI/CD pipeline and prevents PR merges
Priority
Critical
The priority is critical
Priority
High
The priority is high
Priority
Low
The priority is low
Priority
Medium
The priority is medium
When an epic or legendary is in review it must be signed off by owner, tech lead, and scrum master before being marked as completed.
When an epic or legendary is in review it must be signed off by owner, tech lead, and scrum master before being marked as completed.
When an epic or legendary is in review it must be signed off by owner, tech lead, and scrum master before being marked as completed.
A ticket for learning a tool or technology that is needed to be able to do future planning and design.
State
Completed
The ticket has been fully implemented, completed, and merged with the source code. This label should only be applied once a ticket is closed.
State
Duplicate
A ticket that represents the same content as an existing ticket.
State
In Progress
A ticket that is actively being developed.
State
In Review
A ticket that has had some code completed to implement but is waiting to pass peer review and is not yet merged in.
State
Paused
This ticket's work started but wasn't finished. It's on hold (likely in a feature branch) and will be resumed later, either due to a blocker or a delay.
State
Unverified
All new tickets start in this state. A developer may set it to show the ticket is unverified. This means we haven't agreed to work on it. It will either move to a verified state or be closed as wontdo.
State
Verified
The issue has been verified by a developer as legitimate. It will be worked on and verified tickets are now considered part of the backlog.
State
Wont Do
This ticket has been decided it wont be done. This may mean the bug has been determined to not be real (cant verify) or the feature is one we have decided we dont want to adopt.
Type
Automation
Any edits or discussion about the AI automated coding system.
Type
Bug
Something that doesnt work as intended.
Type
Discussion
Anytime a ticket represents a discussion about a subject and doesnt fall into one of the other categories.
Type
Documentation
An error or improvement needed in the documentation.
Type
Epic
Any first tier epic. That is, an epic which contains only issues as children and will not have sub-epics.
Type
Feature
Some new functionality not present.
Type
Legendary
A type of Epic which will contain other Epics.
Type
Refactor
A code change that restructures existing code without changing its external behavior.
Type
Support
Someone needs help using the project.
Type
Task
A generic task that doesnt fit into the other type categories.
Type
Testing
Work exclusively focusing on fixing or expanding testing.
No Label
Type
Task
Projects
Clear projects
No project
Assignees
aditya (Aditya Chhabra)
aleenaumair (Aleena Umair)
brent.edwards (Brent Edwards)
CoreRasurae (Luis Mendes)
drew (Drew Morris)
eugen.thaci (Eugen Thaci)
freemo (Jeffrey Phillips Freeman)
HAL9000 (HAL 9000)
HAL9001 (HAL9001)
hamza.khyari (Hamza Khyari)
hurui200320 (Rui Hu)
justin.morris
khird (Kyle Hird)
org.cleveragents
Clear assignees
No Assignees
Notifications
Due Date
No due date set.
Blocks
Reference: cleveragents/cleveractors-core#74
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Delete Branch "feature/m1-tool-agent-class-injection"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Eliminates the monkey-patching workaround used by
cleveragents-webappto substitute a platform-controlledToolAgentsubclass at runtime. Adds a keyword-onlytool_agent_class: type[ToolAgent] = ToolAgentparameter toAgentFactory.__init__,Executor.__init__,create_executor(), andLLMAgent.__init__. Every internal site that constructs an ephemeralToolAgent— including the LLM agent's multi-turn tool-call loop and all six dispatch paths — now uses the injected subclass.Motivation
cleveragents-webappcurrently monkey-patches fivecleveractorsmodule namespaces at import time to replace theToolAgentclass withPlatformAwareToolAgent. This approach is fragile against library evolution (any new module that importsToolAgentat import time would be missed), import-order sensitive, and breaks static analysis. This PR provides the upstream API extension that removes the need for the monkey-patch entirely — including the LLM tool-calling path and the multi-actor path, which earlier drafts missed.What Changed
src/cleveractors/agents/factory.py(AgentFactory.__init__,_create_agent_instance)tool_agent_class: type[ToolAgent] = ToolAgentargument.ToolAgentsubclass at construction time (fail-fast perCONTRIBUTING.md §Argument Validation).self._tool_agent_classand uses it to populateself.agent_types["tool"], socreate_agent("tool")instantiates the supplied subclass.tool_agent_class=self._tool_agent_classtoLLMAgentwhen creating"llm"-typed agents, so the LLM tool-calling loop honours the injected subclass.src/cleveractors/agents/llm.py(LLMAgent.__init__,_execute_tool_loop)LLMAgent.__init__accepts a keyword-onlytool_agent_class: type[ToolAgent] = ToolAgentargument, validated as aToolAgentsubclass at construction time.self._tool_agent_class(...)across all three dispatch sites (the regular loop, the budget-exhaustion synthesis round, and the post-loop stuck-model synthesis round). Previously these sites importedToolAgent as _TAlocally and constructed the base class directly, which silently bypassed the injected subclass.src/cleveractors/runtime.py(Executor,create_executor)Executor.__init__accepts and validatestool_agent_class, stored asself.tool_agent_class.create_executor()acceptstool_agent_class(keyword-only) and forwards it toExecutor.src/cleveractors/runtime_dispatch.py(all six dispatch paths)_execute_tool: usesexecutor.tool_agent_class(...)instead of the module-levelToolAgent(...)._execute_graphand_execute_graph_stream: passtool_agent_class=executor.tool_agent_classtoAgentFactoryso graph nodes with tool-typed agents pick up the subclass._execute_llmand_execute_llm_stream: passtool_agent_class=executor.tool_agent_classtoAgentFactoryso the single-LLM actor's internally-createdLLMAgent(and its tool-calling loop) honours the injected subclass. (Review-fix round 2) — without this, a single LLM actor that makes tool calls silently fell back to the baseToolAgent._execute_multi_actor: passestool_agent_class=executor.tool_agent_classto the sub-Executorso every actor inside a multi-actor bundle (tool, graph, or LLM) honours the injected subclass. (Review-fix round 2) — without this, all dispatch paths reachable through a multi-actor bundle fell back to the baseToolAgent.ToolAgentimport; the_execute_tooldocstring cross-reference is fully qualified so it still resolves.src/cleveractors/core/application.py(load_configuration,_create_agents)register_agent_type("tool", ToolAgent)call fromload_configurationand the deadtype_mapre-registration block in_create_agents;AgentFactory.__init__already owns the"tool"registration. The"llm"registration is retained as a defensive no-op.features/tool_agent_class_injection.feature+features/steps/tool_agent_class_injection_steps.pyConfigurationError(factory, executor, andLLMAgent);create_agent()returns custom instance;_execute_tooldispatch instantiates custom subclass; the LLM tool loop instantiates the injected subclass;isinstanceLSP compatibility through the factory; the_execute_llmdispatch path forwardingtool_agent_classtoAgentFactory(single-LLM actor making a tool call); and the_execute_multi_actordispatch path forwardingtool_agent_classto the sub-Executor.instantiation_count=0), confirming they guard the injection contract for the single-LLM and multi-actor paths.Test cleanups (consequence of the dispatch-path changes)
features/steps/runtime_coverage_steps.pyandfeatures/steps/runtime_extended_coverage_steps.py: removed the now-deadpatch("cleveractors.runtime_dispatch.ToolAgent")mocks that no longer intercept_execute_toolafter it switched toexecutor.tool_agent_class.features/steps/credential_executor_paths_steps.py: the_execute_multi_actorcredentials-forwarding scenario interceptsExecutor.__init__with acapturing_initto assert the credentials dict reaches the sub-Executor. Now that_execute_multi_actorforwardstool_agent_classto the sub-Executor,capturing_initaccepts and forwards that keyword so the assertion continues to pass.features/application_coverage_gaps.feature: dropped the obsolete_create_agents registers built-in agent typesscenario since the redundant re-registration it asserted was removed.CHANGELOG.md_execute_tool,_execute_graph,_execute_graph_stream,_execute_llm,_execute_llm_stream,_execute_multi_actor) instead of the earlier "All three dispatch paths" wording.Review Fix Rounds
Round 1 (pre-review):
LLMAgenttool loop now uses the injectedtool_agent_class(was constructing baseToolAgent).application.pyredundantToolAgentregistrations; removed unused imports from the new step file.isinstancescenario into a factory-created LSP check; removed the staleToolAgentimport inruntime_dispatch.py; renamed the_fake_processparameter that shadowed Behave'scontext.Round 2 (this revision):
_execute_llmand_execute_llm_streamnow forwardtool_agent_class=executor.tool_agent_classtoAgentFactory(previously omitted, so single-LLM actors with tools fell back to the baseToolAgent)._execute_multi_actornow forwardstool_agent_class=executor.tool_agent_classto the sub-Executor(previously omitted, so every actor inside a multi-actor bundle fell back to the baseToolAgent).CHANGELOG.mdto list all six dispatch paths accurately._execute_multi_actorcredentials-forwarding test'scapturing_initto accept/forward the newtool_agent_classkeyword.Backward Compatibility
Callers that do not pass
tool_agent_classreceive identical behaviour to the previous release — the default isToolAgentitself. No existing callers are affected.cleveragents-webappMigrationAfter this PR merges, update the webapp call site to:
The five-module
setattrloop and_install_platform_tool_hookmachinery can then be deleted — including for the LLM tool-calling path and the multi-actor path, which are now covered.Quality Gates
nox -e lint: pass ✅nox -e typecheck(pyright strict): 0 errors ✅nox -e unit_tests: 2756 scenarios, 0 failures ✅nox -e coverage_report: 97.0% (threshold 96.5%) ✅nox -e integration_tests: pass ✅Closes #73
Extends AgentFactory.__init__ and create_executor() with a keyword-only tool_agent_class: type[ToolAgent] = ToolAgent parameter so callers can inject a custom ToolAgent subclass at runtime without monkey-patching module globals (resolves the five-module setattr loop in cleveragents-webapp). **AgentFactory** (agents/factory.py): - Accepts tool_agent_class keyword argument; validates it is a ToolAgent subclass at construction time (fail-fast, CONTRIBUTING.md §Argument Validation). - Stores as self._tool_agent_class and uses it to populate self.agent_types['tool'], so every create_agent('tool') call instantiates the supplied subclass. - Default ToolAgent is preserved, so all existing callers are unaffected. **Executor / create_executor** (runtime.py): - Executor.__init__ accepts and validates tool_agent_class; stores as self.tool_agent_class. - create_executor() accepts tool_agent_class and forwards it to Executor. **Dispatch paths** (runtime_dispatch.py): - _execute_tool: replaces ToolAgent(...) with executor.tool_agent_class(...) so the direct-construction path (bypassing AgentFactory) also honours the injected subclass. - _execute_graph and _execute_graph_stream: pass tool_agent_class=executor.tool_agent_class to AgentFactory so graph nodes using tool-typed agents pick up the subclass. **Tests** (features/tool_agent_class_injection.feature + steps): - 13 BDD scenarios covering: default class when parameter omitted; custom subclass stored on factory and executor; invalid class rejected with ConfigurationError; factory create_agent returns custom instance; _execute_tool dispatch instantiates custom subclass; isinstance LSP compatibility. **Updated test** (features/steps/runtime_extended_coverage_steps.py): - _execute_tool now uses executor.tool_agent_class instead of the module-level ToolAgent name; updated the mock strategy from patch('cleveractors.runtime_dispatch.ToolAgent') to patch.object(ToolAgent, 'process_message', ...) so the existing coverage scenario continues to pass. ISSUES CLOSED: #73LGTM ✅ — self-review complete. Implementation is correct, tests pass, CI green, coverage 97.0%.
20f68e9ae4to3ead0cc7a83ead0cc7a8to8ad12ac0758ad12ac075to0646b3e958Self-QA Approval
This PR has passed internal self-QA review after 3 review/fix cycles.
Summary
tool_agent_classinjection is correctly implemented acrossAgentFactory,Executor,create_executor, andLLMAgent._execute_tool,_execute_graph,_execute_graph_stream,_execute_llm,_execute_llm_stream,_execute_multi_actor.ToolAgent).Quality Gates
Approved for merge. 🚀
0646b3e958to9ec578f229