Skip to content

Refactor AgentScope Studio #586

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
May 1, 2025
Merged

Refactor AgentScope Studio #586

merged 11 commits into from
May 1, 2025

Conversation

DavdGao
Copy link
Collaborator

@DavdGao DavdGao commented Apr 24, 2025

Description

This PR is part of the AgentScope Studio refactoring initiative.

Changes

  1. Enhanced User Agent Implementation

    • Added a _input_method attribute (callable) to handle user input from various sources
    • Implemented two built-in input handlers:
      • TerminalUserInput for command-line interactions
      • StudioUserInput for studio-based interactions
    • Provided flexibility for developers to integrate custom frontend input sources
  2. Improved Model Wrapper Architecture

    • Introduced _class_hooks_save_model_invocation attribute in ModelWrapperBase class to support model invocation recording
    • Created ChatUsage class to standardize usage metrics for chat-based LLMs
  3. Architecture Optimization

    • Planning to deprecate global _studio_client variable and StudioClient class
    • Transitioning to a distributed interaction model where studio communications are handled directly by individual agent instances

Note: This refactoring aims to reduce dependency on the agentscope.init function by distributing functionality to relevant objects (e.g., model wrappers, agents) through hooks.

Checklist

Please check the following items before code is ready to be reviewed.

  • Code has passed all tests
  • Docstrings have been added/updated in Google Style
  • Documentation has been updated
  • Code is ready for review

@DavdGao DavdGao changed the title [WIP] Refactor user agent for new AgentScope Studio [WIP] Refactor AgentScope Studio Apr 24, 2025
@DavdGao DavdGao changed the title [WIP] Refactor AgentScope Studio Refactor AgentScope Studio Apr 27, 2025
@DavdGao DavdGao requested a review from Copilot April 27, 2025 05:54
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors AgentScope Studio by enhancing user agent input handling, refactoring model invocation recording with a new usage metric model, and optimizing the overall architecture by reducing reliance on the global studio client.

  • Enhanced User Agent Implementation with custom input sources
  • Improved Model Wrapper Architecture using ChatUsage for consistent usage tracking
  • Optimized architecture by replacing global StudioClient references with direct HTTP API calls

Reviewed Changes

Copilot reviewed 122 out of 122 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/agentscope/models/yi_model.py Added ChatUsage usage handling for formatting and updating monitor tokens.
src/agentscope/models/openai_model.py Integrated ChatUsage for model invocation recording with condition checks for required tokens.
src/agentscope/models/ollama_model.py Refactored usage handling by wrapping token counts in ChatUsage.
src/agentscope/models/model.py Introduced _class_hooks_save_model_invocation and integrated ChatUsage usage into invocation records.
src/agentscope/models/litellm_model.py Added ChatUsage usage integration; note potential inconsistency in passing usage to model invocation.
src/agentscope/models/gemini_model.py Updated token utilization formatting using ChatUsage.
src/agentscope/models/dashscope_model.py Replaced direct token value references with ChatUsage usage formatting in monitor update and invocation.
src/agentscope/models/anthropic_model.py Incorporated ChatUsage usage handling for model invocation and monitor update.
src/agentscope/models/_model_usage.py Introduced the ChatUsage model for standardized usage metrics.
src/agentscope/manager/_manager.py Replaced StudioClient integration with direct HTTP calls and added hooks for model invocation pushing.
src/agentscope/logging.py Removed StudioClient-dependent logging and gradio integration for a cleaner logging output.
src/agentscope/agents/_user_input.py Added StudioUserInput and TerminalUserInput classes for flexible user input handling.
src/agentscope/agents/_user_agent.py Added input method override functions and updated user input integration in reply generation.
src/agentscope/agents/_react_agent_v2.py Updated agent reply to use the speak method for message dispatch.
src/agentscope/agents/_agent.py Introduced _reply_id generation to uniquely identify agent replies.
examples/environments/chatroom/envs/chatroom.py Updated chat room agent to extend UserAgent and utilize the new input method.
examples/distributed_debate/user_proxy_agent.py Adjusted user proxy agent reply signature to use structured output.
setup.py Removed unused studio static assets to match the refactored architecture.

@DavdGao DavdGao merged commit 213362f into modelscope:main May 1, 2025
13 checks passed
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