Skip to content

Dev#13

Merged
ayusrjn merged 5 commits into
mainfrom
dev
Apr 10, 2026
Merged

Dev#13
ayusrjn merged 5 commits into
mainfrom
dev

Conversation

@ayusrjn
Copy link
Copy Markdown
Member

@ayusrjn ayusrjn commented Apr 10, 2026

Summary by CodeRabbit

  • New Features

    • Token usage tracking displayed per turn and session-wide.
    • Persistent session transcript logging.
    • Support for multiple Gemini models with mid-session model switching.
    • Persistent scratchpad for session notes (read, write, update, clear operations).
    • Slash commands for model selection (/models), configuration (/config), and help (/help).
    • Mid-session API key updates via configuration interface.
  • Improvements

    • Enhanced UI with Rich formatting, styled panels, and better output rendering.
    • Chat history optimization and tool iteration safeguards.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 10, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c19b84c1-0bb7-442b-a0a8-852ae29305d5

📥 Commits

Reviewing files that changed from the base of the PR and between 6bf1808 and 8d76a19.

📒 Files selected for processing (8)
  • lambda_agent/agent.py
  • lambda_agent/config.py
  • lambda_agent/context.py
  • lambda_agent/main.py
  • lambda_agent/scratchpad.py
  • lambda_agent/spinner.py
  • lambda_agent/tools.py
  • requirements.txt

📝 Walkthrough

Walkthrough

This PR enhances the lambda agent with token usage tracking, persistent transcript and scratchpad logging, Rich-based UI styling, chat history trimming, model switching capability, and tool iteration limits. It refactors the spinner to use Rich's Live API and expands the command interface with slash commands and configuration updates.

Changes

Cohort / File(s) Summary
Core Agent Logic
lambda_agent/agent.py, lambda_agent/config.py, lambda_agent/context.py
Added TokenUsage dataclass to track prompt/completion tokens per session; introduced persistent append-only Transcript JSONL logging; disabled Gemini automatic function calling and changed tool-response dispatch; added switch_model(new_model) method; expanded system_instruction content; changed chat() return type to tuple[str, TokenUsage]; implemented tool iteration cap at 10 iterations; added slide-window chat history trimming via trim_chat_history(). Added AVAILABLE_MODELS constant listing supported Gemini models.
Scratchpad & File Management
lambda_agent/scratchpad.py
New module implementing persistent Markdown scratchpad file (.agent/scratchpad.md) with CRUD operations: read_scratchpad(), write_scratchpad(), update_scratchpad(), clear_scratchpad(). Exposes SCRATCHPAD_EXECUTORS and SCRATCHPAD_FUNCTIONS registries for tool integration.
UI & Interaction
lambda_agent/main.py, lambda_agent/spinner.py, lambda_agent/tools.py
Replaced manual thread-based spinner with Rich-based Live context manager; updated main.py to use Rich console for styled output (panels, prompts, token stats); added slash-command handling (/models, /config, /help); implemented mid-session API key/model updates persisting to disk; enhanced error rendering and shutdown sequences. Updated ask_user tool with Rich Panel UI and merged scratchpad tool executors into tool registry.
Dependencies
requirements.txt
Added rich>=13.7.0 dependency.

Sequence Diagram(s)

sequenceDiagram
    actor User
    participant Main as Main REPL
    participant Agent
    participant ChatSession as Gemini Chat Session
    participant Tools
    participant Transcript
    participant TokenUsage as TokenUsage Tracker

    User->>Main: User input
    Main->>Agent: chat(user_input)
    
    Agent->>Agent: Store system_instruction
    Agent->>ChatSession: send_message(user_input)
    ChatSession->>ChatSession: Initial response
    ChatSession-->>Agent: Response + usage_metadata
    
    Agent->>TokenUsage: _accumulate(response)
    TokenUsage->>TokenUsage: Update prompt/completion totals
    Agent->>Transcript: log(role="user", content=user_input)
    Agent->>Transcript: log(role="assistant", content=response_text)
    
    alt Tool calls detected
        Agent->>Agent: Tool iteration loop (max 10)
        loop For each tool call
            Agent->>Tools: Execute tool
            Tools-->>Agent: Tool result
            Agent->>Transcript: log tool call metadata
            Agent->>Transcript: log tool result
            Agent->>ChatSession: send_message(tool_responses)
            ChatSession-->>Agent: Response + usage_metadata
            Agent->>TokenUsage: _accumulate(response)
        end
    end
    
    Agent->>Agent: trim_chat_history()
    Agent->>Transcript: log final assistant response
    Agent-->>Main: (response_text, TokenUsage)
    
    Main->>Main: Print formatted response
    Main->>Main: Print token usage stats
    Main-->>User: Rendered output + token summary
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~75 minutes

Possibly related PRs

  • Dev #7: Overlapping changes to lambda_agent/agent.py including GenAI client/API usage, spinner integration, and tool/function-call handling refactoring.
  • feat:Implemented Ask Tool #12: Modifies agent system_instruction content and alters the ask_user tool registration and behavior.

Poem

🐰 Hop, hop! The tokens now traced,
Transcripts logged, scratchpads embraced,
Rich panels gleam, spinners now spin,
Model switching—let the flow begin!
⏳ ✨

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch dev

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Comment thread lambda_agent/main.py Dismissed
@ayusrjn ayusrjn merged commit 533d5f4 into main Apr 10, 2026
2 of 3 checks passed
@coderabbitai coderabbitai Bot mentioned this pull request Apr 12, 2026
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants