feat(ActorResult): implement ActorResult and NodeUsage types; capture per-node token counts from LangChain responses #14
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 milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Blocks
Depends on
#15 feat(execution-limits): add structured ExecutionError kind/reason fields; enforce all 5 execution limits in PureLangGraph
cleveragents/cleveractors-core
#16 feat(streaming): add Executor.execute_stream() returning AsyncIterator[str] for token-by-token delivery
cleveragents/cleveractors-core
#17 feat(public-api): expose all router-facing APIs at cleveractors package level; update README
cleveragents/cleveractors-core
You do not have permission to read 2 dependencies
#12 feat(credentials): refactor LLMAgent/AgentFactory for per-request credential injection and extended provider routing
cleveragents/cleveractors-core
Reference
cleveragents/cleveractors-core#14
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?
Background
Executor.execute()currently returns a plainstr. The CleverThis router needs per-node token counts to calculate billing —prompt_tokensandcompletion_tokensfrom each LLM node invocation. These must be returned by the library; the router must not import LangChain directly.Currently
LLMAgent.process_message()reads onlyresponse.contentfrom the LangChain response and discards all usage metadata.Spec references: ADR-2027 (ActorResult and Token Counting), Actor Configuration Standard Glossary
Depends on: #13 —Implement concurrently with #13 on the same feature branch. The structural precondition (Executormust exist beforeexecute()return type can be updated.Executorexisting) is already met by the bot's partial implementation. Both tickets are blocked on #12 and both require modifying the same two methods (_execute_llm()and_execute_graph()inruntime.py) — splitting them across separate branches would cause double-churn and merge conflicts on those methods.Current State (Post-Bot Commit
e7a7d39)A bot pushed
e7a7d39directly tomaster, partially touching the scope of this ticket.Three critical deviations from the spec remain:
Wrong module location:
ActorResultandNodeUsageare defined inruntime.pyrather than the spec'dcleveractors/result.py. All imports and__init__.pyre-exports must be updated after the move.Estimated tokens instead of real LangChain metadata: Every execution path calls
_estimate_tokens()(tiktoken when available, 4-chars/token heuristic otherwise). AC2 mandates extraction fromresponse.usage_metadatawithresponse.response_metadata.get("token_usage", {})as fallback.LLMAgentandPureLangGraphinternals untouched:process_message()and_execute_from_node()still discard all usage metadata — the bot'sExecutorbypasses them entirely and estimates instead.What Is Currently Missing
cleveractors/result.pydoes not exist —ActorResultandNodeUsageare stranded inruntime.py(wrong location per AC1).LLMAgent.process_message()reads onlyresponse.content— no token usage captured.PureLangGraph._execute_from_node()does not collect per-node token data.Executor.execute()returnsActorResult✅ but all token counts are estimated (_estimate_tokens()), not read from LangChainusage_metadata.Acceptance Criteria
cleveractors/result.py:LLMAgent.process_message()extracts token usage fromresponse.usage_metadata(primary) with fallback toresponse.response_metadata.get("token_usage", {}). If no usage data is available: log a warning and use0.process_message()returns token counts alongside the response string.PureLangGraph._execute_from_node()collects(node_id, provider, model, prompt_tokens, completion_tokens)per LLM node invocation.Executor.execute()aggregates intoActorResultand returns it (breaking change fromstr).result.prompt_tokens == sum(n.prompt_tokens for n in result.nodes).ActorResultandNodeUsageexported fromcleveractors/__init__.pyand__all__.Subtasks
cleveractors/result.py; moveNodeUsageandActorResultfromruntime.pyinto it; updateruntime.pyimportLLMAgent.process_message()to extract and return token usage from LangChain response (usage_metadataprimary,response_metadata["token_usage"]fallback)PureLangGraph._execute_from_node()to collect per-node token usage and thread it back throughLLMAgent_estimate_tokens()fromruntime.py; updateExecutor._execute_llm()and_execute_graph()to use real token counts from the refactoredLLMAgent/PureLangGraph(coordinate with #13 — both modify the same methods)ActorResultandNodeUsagefromcleveractors/__init__.pyand__all__(done; verify import path afterresult.pymove)Definition of Done
executor.execute(msg)returnsActorResultwithresponse,prompt_tokens,completion_tokens, andnodes.from cleveractors import ActorResult, NodeUsageworks without error.hurui200320 referenced this issue2026-06-08 12:27:52 +00:00