Skip to content

fix: invoke print hooks before console output check#1328

Open
KJyang-0114 wants to merge 1 commit intoagentscope-ai:mainfrom
KJyang-0114:fix/studio-hook-when-console-disabled
Open

fix: invoke print hooks before console output check#1328
KJyang-0114 wants to merge 1 commit intoagentscope-ai:mainfrom
KJyang-0114:fix/studio-hook-when-console-disabled

Conversation

@KJyang-0114
Copy link

Summary

This fixes issue #1149 where set_console_output_enabled(False) also disabled AgentScope Studio forwarding.

Root Cause

The print() method in AgentBase checked _disable_console_output and returned early before any hooks were invoked. This meant the Studio pre_print hook never ran when console output was disabled.

Fix

Invoke pre_print and post_print hooks before the console output check. This decouples Studio/tracing from console output:

  • set_console_output_enabled(False) now only disables console printing
  • Studio continues to receive messages, metadata, and traces

Changes

  • src/agentscope/agent/_agent_base.py:
    • Added invocation of pre_print hooks before the early return
    • Added invocation of post_print hooks after console output (but before cleanup)

Testing

  • Syntax validation passed
  • Manual test: Enable Studio, disable console output, verify messages still appear in Studio

Risk

  • Low: Only adds hook invocations, no behavior changes to existing console output logic

Rollback

Simply revert this commit to restore previous behavior.

This fixes the issue where set_console_output_enabled(False) also
disabled AgentScope Studio forwarding. Now pre_print and post_print
hooks are invoked BEFORE the console output check, allowing Studio
to receive messages even when console output is disabled.

This decouples Studio/tracing from console output, enabling users to:
- Disable console logs in production
- Keep Studio/tracing enabled for observability

Fixes agentscope-ai#1149
@cla-assistant
Copy link

cla-assistant bot commented Mar 15, 2026

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


Coder seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

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.

1 participant