Add tool_agent_class parameter to AgentFactory and create_executor to support runtime-injected ToolAgent subclasses
#73
Closed
opened 2026-07-07 06:40:16 +00:00 by hurui200320
·
3 comments
No Branch/Tag Specified
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.
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
hurui200320
Notifications
Due Date
No due date set.
Depends on
#74 feat(agents): add tool_agent_class parameter to AgentFactory and create_executor
cleveragents/cleveractors-core
Reference: cleveragents/cleveractors-core#73
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 "%!s()"
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?
Metadata
Commit Message:
feat(agents): add tool_agent_class parameter to AgentFactory and create_executorBranch:
feature/m1-tool-agent-class-injectionBackground
cleveractors-coreis consumed bycleveragents-webapp(thecleverthisplatform). The webapp needs to replace theToolAgentclass used at runtime with a project-controlled subclass —PlatformAwareToolAgent— that overrides_validate_tools()to register native async handlers for platform-approved tools (e.g.cleverthis/safe-http-fetch). This bridges the gap betweenToolAgent's Python-sandbox execution model and the webapp's server-side handler registry: without the override, platform tools have no code to run.Because
cleveractorsdoes not currently expose any extension point for customising theToolAgentimplementation, the webapp works around this limitation by monkey-patching fivecleveractorsmodule namespaces at import time:This is guarded by an
_hook_installedflag (idempotent), protected by atry/except, and explicitly documented as a monkey-patch in the module docstring. It works correctly today. However, it carries several structural risks that are best resolved by an upstream API change:cleveractorsmodule importsToolAgentat its own import time (e.g. a futureworkers.py), the patch silently misses it. The failure only surfaces at runtime when that module constructs aToolAgentinstance, and platform tools silently don't execute.platform_toolsis first imported. Anycleveractorsmodule initialised beforeplatform_toolsis imported will hold a stale reference for the duration of its module-level setup. This is currently avoided by application startup order, but is a latent ordering hazard.ToolAgentthroughout allcleveractorscall sites. Types derived from the patched class are invisible to the checker, making strict-mode findings in those modules silently incorrect.cleveragents-webappis coupled tocleveractors's internal module structure rather than a stable public API.Proposed Solution
Extend
AgentFactory.__init__(and, transitively,create_executor) to accept an optionaltool_agent_classkeyword argument. When provided, this class is used in place of the defaultToolAgentwherever the factory constructs tool agents — in the type registry, in_execute_toolconstruction, inisinstancechecks, and in LangGraph node wiring.Sketch of the
AgentFactorychange:Every internal site that currently references the module-level
ToolAgentsymbol is replaced withself._tool_agent_class.create_executorforwards the parameter:Resulting
cleveragents-webappcall site (afterplatform_tools.pyis updated to use the new API):The five-module
setattrloop and the_install_platform_tool_hookmachinery incleveragents-webappare deleted entirely once this parameter exists.Acceptance Criteria
AgentFactory.__init__accepts an optionaltool_agent_class: type[ToolAgent]keyword argument, defaulting toToolAgent.tool_agent_classis provided, every internalAgentFactorycode path that constructs, type-checks (isinstance), or registers aToolAgentuses the supplied class instead of the module-level default.create_executoraccepts and forwardstool_agent_classtoAgentFactory.tool_agent_class.cleveractorsor in the webapp's updated call site.isinstancechecks when parameter is provided.CHANGELOG.mdupdated with one entry for this commit.Subtasks
AgentFactory(factory, dispatch, application, langgraph nodes) that reference theToolAgentsymbol and list them.tool_agent_classparameter toAgentFactory.__init__; replace all audited sites withself._tool_agent_class.tool_agent_classparameter tocreate_executor; forward toAgentFactory.CHANGELOG.md.cleveragents-webappteam so they can update thepyproject.tomlpin and replace_install_platform_tool_hookwith the newcreate_executorargument.Definition of Done
AgentFactoryandcreate_executoraccepttool_agent_classwith backward-compatible default.cleveractorsquality gates pass (noxsuite green, coverage ≥ threshold, Pyright strict clean).main/master.cleveragents-webappteam notified (comment on this issue with the new pinned commit SHA or release tag once available).Implementation Notes — Audit & Design Decisions
Audit: ToolAgent references across
cleveractorsSearched all
.pyfiles insrc/cleveractors/forToolAgentreferences:agents/tool.pyagents/factory.pyself.agent_types["tool"] = ToolAgentself._tool_agent_classruntime_dispatch.pyagent = ToolAgent(...)in_execute_toolexecutor.tool_agent_classcore/application.pyregister_agent_type("tool", ToolAgent), L934 type_mapReactiveCleverAgentsApp— separate entry pointcreate_executorpath; note below)langgraph/nodes.pyisinstance(agent, ToolAgent)isinstancenatively supports subclasses via LSPDesign Decisions
1. Scope of the change
The issue asks to fix
AgentFactoryandcreate_executor. TheReactiveCleverAgentsAppincore/application.pyis a separate, higher-level entry point (CLI/interactive mode) and is not reachable fromcreate_executor. Changing it would require a separate parameter threading path and is out of scope for this issue. A note will be added to the issue for follow-up.2. Where to carry
tool_agent_classonExecutorThe cleanest approach is to store
tool_agent_classonExecutoritself (asself.tool_agent_class). All dispatch functions already receiveexecutoras their first argument, so they can accessexecutor.tool_agent_classwithout signature changes.3.
isinstancechecks inlanggraph/nodes.pyisinstance(agent, ToolAgent)already works correctly for subclasses because Python'sisinstancechecks the MRO. No change is needed — aPlatformAwareToolAgent(ToolAgent)subclass will pass these checks correctly.4. Type annotation
tool_agent_class: type[ToolAgent] = ToolAgentusestype[ToolAgent]which accepts any subclass ofToolAgentin Pyright strict mode. This is the correct, fully-typed approach.5. Argument validation
Per
CONTRIBUTING.md §Argument Validation, public methods must validate arguments. We'll addissubclass(tool_agent_class, ToolAgent)guard inAgentFactory.__init__andExecutor.__init__to reject non-ToolAgentclasses at the entry boundary (fail-fast).6.
_execute_graphand_execute_graph_stream(AgentFactory creation)Both functions create an
AgentFactoryfor graph execution. They must passtool_agent_class=executor.tool_agent_classto the factory so graph nodes usingToolAgentalso pick up the subclass.Files to Modify
src/cleveractors/agents/factory.py— addtool_agent_classparamsrc/cleveractors/runtime.py— addtool_agent_classtoExecutorandcreate_executorsrc/cleveractors/runtime_dispatch.py— thread through in_execute_tool,_execute_graph,_execute_graph_streamfeatures/tool_agent_class_injection.feature— new BDD feature filefeatures/steps/tool_agent_class_injection_steps.py— new step definitionsCHANGELOG.md— one entryWebapp Team Notification
PR #74 (
feat(agents): add tool_agent_class parameter to AgentFactory and create_executor) has been submitted for review.Once this PR is merged, the
cleveragents-webappteam can:Update the
pyproject.tomlpin to reference the new release tag (or commit SHA) that includes this change.Replace
_install_platform_tool_hookwith the newcreate_executorkeyword argument:The five-module
setattrloop and all_install_platform_tool_hookmachinery incleverthis/services/platform_tools.pycan then be removed.Commit SHA:
20f68e9ae4eacbf050d30efce550f8d9584e44c4(on branchfeature/m1-tool-agent-class-injection, PR #74)Self-QA Implementation Notes (Cycles 1–3)
Cycle 1
Review findings: 0 Critical / 1 Major / 3 Minor / 3 Nits
LLMAgentinternal tool-call loop still imported and constructed baseToolAgentvia_TA(...), ignoring the injected subclass. This left the LLM tool-calling path dependent on the monkey-patch.ReactiveCleverAgentsApphardcodedToolAgentinload_configurationand_create_agents; missing test coverage for LLM tool loop with custom subclass; unused imports (asyncio,AsyncMock,MagicMock) in new step file.isinstancescenario (direct instantiation instead of factory-created); staleToolAgentimport inruntime_dispatch.py;contextparameter shadowed Behavecontextin_fake_processhelper.Fixes applied:
tool_agent_class: type[ToolAgent] = ToolAgentkeyword-only parameter toLLMAgent.__init__with fail-fast subclass validation. Stored asself._tool_agent_classand replaced all three_TA(...)constructions inllm.pywithself._tool_agent_class(...).AgentFactory._create_agent_instanceto forwardtool_agent_classwhen creating"llm"-typed agents.register_agent_type("tool", ToolAgent)and deadtype_mapre-registration fromReactiveCleverAgentsAppinapplication.py.LLMAgentrejection scenario for coverage of the new validation branch.isinstancescenario with factory-mediated LSP test; removed staleToolAgentimport fromruntime_dispatch.py(updated docstring reference) and removed now-deadpatch("cleveractors.runtime_dispatch.ToolAgent")mocks in two test files._fake_processparameter to**_kwargsto eliminate Behavecontextshadowing.CHANGELOG.mdand PR description.Cycle 2
Review findings: 0 Critical / 2 Major / 2 Minor / 0 Nits
_execute_llmand_execute_llm_streamconstructedAgentFactorywithout forwardingtool_agent_class, so single LLM actors fell back to baseToolAgent._execute_multi_actorbuilt a sub-Executorwithout forwardingtool_agent_class, breaking injection for multi-actor bundles.CHANGELOGoverstated dispatch-path coverage as "all three" when six paths exist.Fixes applied:
tool_agent_class=executor.tool_agent_classtoAgentFactory(...)calls in_execute_llmand_execute_llm_stream(runtime_dispatch.py).tool_agent_class=executor.tool_agent_classto sub-Executor(...)constructor in_execute_multi_actor.CHANGELOG.mdto accurately list all six dispatch paths.credential_executor_paths_steps.pytest:capturing_initsignature extended to accept and forwardtool_agent_class, preventingTypeErrorfrom the new forwarding behavior.Cycle 3
Review findings: 0 Critical / 0 Major / 5 Minor / 3 Nits
tool_agent_class_injection_steps.pyexceeds 500-line guideline (720 lines); missing explicit BDD coverage for_execute_graph,_execute_graph_stream,_execute_llm_stream; no Robot integration test for injected subclass;ReactiveCleverAgentsAppstill does not exposetool_agent_class;RecordingToolAgentcounter increments beforesuper().__init__().Executor.__init__missing-> Noneannotation; several# type: ignorecomments;tool_agent_classforwarded only for exactagent_type == "llm"in factory.Fixes applied: None — all remaining items are polish/extension suggestions rather than correctness defects. The review agent approved the PR.
Remaining Issues
None blocking. The following are acknowledged follow-ups / polish items deferred to future work:
tool_agent_classinjection.ReactiveCleverAgentsAppdoes not exposetool_agent_class(platform usescreate_executorentry point per ticket scope).RecordingToolAgentcounter placement and minor type-annotation nits.All quality gates pass: 2756 Behave scenarios, 0 failures; 319 integration tests passed; 97.0% coverage (threshold 96.5%). CI run #30677 success.