Add session usage ledger and refine step-loop plan handling - #154
Merged
Conversation
…a SessionUsageProxy
Contributor
There was a problem hiding this comment.
Sorry @JohnRichard4096, your pull request is larger than the review limit of 150000 diff characters
Member
Author
|
@sourcery-ai title |
Contributor
Reviewer's GuideThis PR introduces a run-scoped usage ledger wired into libchat and strategies, refactors token accounting and step-loop behaviors to use the ledger instead of ad-hoc accumulation, hardens MCP client connection management under concurrency, and extends the ReAct step-loop strategy with plan-status injection, tool-failure guidance, and correct reasoning_content round-tripping, along with updated demos, docs, and tests. Sequence diagram for tool_failure_hint_and_plan_revision_in_step_loopsequenceDiagram
participant Strategy as ReActAgentStrategy
participant RunState as AgentRunState
participant LLM as Model
Strategy->>RunState: _init_run_state()
Strategy->>LLM: single_execute (tools_caller)
LLM-->>Strategy: ToolCall db_query
Strategy->>Strategy: _exec_one(tc)
Strategy-->>Strategy: func_response="ERROR: ..."
Strategy->>Strategy: _append_tool_result_to_context(tool_call, func_response)
Strategy->>Strategy: _maybe_inject_tool_failure_hint(tool_call, func_response)
Strategy->>RunState: tool_error_hints += 1
Strategy->>LLM: Message role=user (failure_hint)
LLM-->>Strategy: ToolCall update_step
Strategy->>Strategy: _handle_update_step(args)
Strategy->>RunState: plan_revision += 1
Strategy-->>LLM: ToolResult "<STEP_PLAN_UPDATED> revised plan: ..."
Strategy->>RunState: leave_step()
Strategy->>RunState: begin_step("execute")
Strategy->>RunState: step_started_ts = time.time()
Strategy->>Strategy: _inject_plan_status()
Strategy-->>LLM: Message role=user ("[Plan status]\n- node_id [state]: ...")
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary by Sourcery
Introduce a run-scoped usage ledger, strengthen the step-driven ReAct workflow (plan visibility, autonomous revision, token budgeting), harden MCP client concurrency, and update docs/demos to reflect explicit step-loop opt-in and adapter/provider behavior.
New Features:
Bug Fixes:
Enhancements:
Documentation:
Tests:
Chores: