feat(agents): add tool-call support to LLMAgent.stream_message #68
No reviewers
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.
Blocks
#67 Add tool-call support to LLMAgent.stream_message
cleveragents/cleveractors-core
Reference
cleveragents/cleveractors-core!68
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "feature/m2-llm-agent-stream-tool-calls"
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
Fixes the capability gap where
execute_stream()on a tool-declaring LLM actor yielded an empty or hallucinated response. Extracts the entire multi-turn tool-call orchestration fromprocess_message()into a shared private_execute_tool_loop()helper that bothprocess_message()andstream_message()now call.Motivation
process_message()had a fully working multi-turn tool-call loop (~490 lines).stream_message()had none of this — it calledastream()without passingtools, so the LLM received no tool schemas and produced no structured tool calls.Duplicating the loop into
stream_message()would create a permanent maintenance burden with two diverging implementations. The correct fix is extraction into a shared helper.Approach
New types (module level in
llm.py)_ToolLoopResultdataclass: carriesfinal_response,accumulated_prompt,accumulated_completion,budget_exhausted,synthesis_was_run. Both callers read token counts from this object._ToolLoopErrorexception: wraps any exception raised inside the helper and carries partial accumulated token counts +any_invocation_madeflag. Callers catch this, set billing sentinels, then re-raise the originalcause from None._execute_tool_loop()(new method onLLMAgent)Contains the full tool orchestration extracted verbatim from
process_message():tool_max_roundsfrom config/envinvoke_kwargswith tools (+ pruning augmentation when enabled)ainvoke()looptool_callto an ephemeralToolAgent_ToolLoopErrorcarrying partial countsprocess_message()refactorReplaces ~490 lines of inline tool loop with a 15-line delegation. Observable behaviour is identical — all 63 existing
llm_agent_tool_calling.featurescenarios pass unmodified.stream_message()integration_execute_tool_loop(), yields the final response as a single content chunk, sets_last_token_usagefrom the result's accumulated token counts.astream()token-by-token path runs completely unchanged.Single-chunk trade-off: when tools are involved, the user already waits for tool execution before the final answer begins, so yielding that answer as one chunk vs. token-by-token has minimal UX impact. The alternative (re-calling
astream()afterainvoke()produced the final response) would double LLM cost for every tool-using request.Tests
features/llm_agent_tool_loop.feature(10 scenarios):_execute_tool_loop()internals tested independently — single round, multi-round, max_rounds exhaustion, token accumulation, budget exhaustion, stuck-model synthesis, pruning pass, tool dispatch error, exception path, pre-invocation ConfigurationError.features/llm_agent_stream_tool_calls.feature(7 scenarios):stream_message()integration — single-chunk output, two-round token sum, final text, no-tools astream unchanged, no-tools token counts, exception billing integrity, memory update.robot/llm_tool_calling.robot(2 new cases):execute_stream()on tool-configured actor exercises the tool loop path; multi-round token accumulation equals sum of all rounds.Quality gates
Follow-up
The webapp workaround
actor_config_has_tools+stream_fallback_to_non_streamincleveragents/cleveragents-webapp#328can now be removed.Closes #67
Self-QA Review: Approved ✅
PR reviewed in 1 cycle.
Verdict: Approve — ready to merge.
Issues found: 0 Critical / 0 Major / 3 Minor / 5 Nits
Minor findings (non-blocking)
final_response is not None(tautological); should verifysynthesis_was_run=True._ToolLoopError— docstring showsraise tle.cause, callers useraise _tle.cause from None.breakvscontinueinconsistency — budget-exhaust synthesis path usesbreakon undeclared tool names while other paths usecontinue; preserved verbatim from original code, safe to defer to cleanup.Nits
# type: ignorein new test files violates project policy._execute_tool_loop()._ToolLoopError.__init__acceptsBaseExceptionbut wrapper only catchesException._tool_token_strvariable name instream_message()is misleading.All 11 acceptance criteria from #67 are satisfied. None of the above are blockers; they can be addressed in a follow-up cleanup commit if desired.
306f114b8a85b429cfb085b429cfb09bd766c3839bd766c3834141469ac94141469ac9306f114b8a