Add tool_agent_class parameter to AgentFactory and create_executor to support runtime-injected ToolAgent subclasses #73
Labels
No 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
Bounty
$100
Bounty
$1000
Bounty
$10000
Bounty
$20
Bounty
$2000
Bounty
$250
Bounty
$50
Bounty
$500
Bounty
$5000
Bounty
$750
MoSCoW
Could have
MoSCoW
Must have
MoSCoW
Should have
Needs Feedback
Points
1
Points
13
Points
2
Points
21
Points
3
Points
34
Points
5
Points
55
Points
8
Points
88
Priority
Backlog
Priority
CI Blocker
Priority
Critical
Priority
High
Priority
Low
Priority
Medium
Signed-off: Owner
Signed-off: Scrum Master
Signed-off: Tech Lead
Spike
State
Completed
State
Duplicate
State
In Progress
State
In Review
State
Paused
State
Unverified
State
Verified
State
Wont Do
Type
Automation
Type
Bug
Type
Discussion
Type
Documentation
Type
Epic
Type
Feature
Type
Legendary
Type
Refactor
Type
Support
Type
Task
Type
Testing
No project
No assignees
1 participant
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
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
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)type: toolgraph node execution by wiringNodeConfig.tooltoToolAgent._execute_tool#75Self-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.