Skip to content

fix: 使用 ResultMessage.result 获取最终响应#8

Merged
BukeLy merged 2 commits intomainfrom
fix/use-result-message-for-response
Jan 4, 2026
Merged

fix: 使用 ResultMessage.result 获取最终响应#8
BukeLy merged 2 commits intomainfrom
fix/use-result-message-for-response

Conversation

@BukeLy
Copy link
Owner

@BukeLy BukeLy commented Jan 4, 2026

Summary

  • 改用 ResultMessage.result 替代手动收集 AssistantMessageTextBlock
  • 符合 Claude Agent SDK 设计意图,ResultMessage.result 包含完整聚合响应
  • 移除不再需要的 AssistantMessageTextBlock 导入

Test plan

  • 添加 tests/test_sdk_response.py 验证 SDK 消息结构
  • 在 Telegram 测试 /hello-world 确认响应正常

- 改用 ResultMessage.result 替代手动收集 AssistantMessage 的 TextBlock
- 符合 SDK 设计意图,ResultMessage.result 包含完整聚合响应
- 移除不再需要的 AssistantMessage 和 TextBlock 导入
- 添加 SDK 响应结构测试用于验证消息类型
Copilot AI review requested due to automatic review settings January 4, 2026 11:22
Copy link
Contributor

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 the response handling in the Claude Agent SDK integration to use ResultMessage.result for the final aggregated response instead of manually collecting text from AssistantMessage content blocks. This aligns with the SDK's intended design pattern.

Key changes:

  • Replaced manual text collection from AssistantMessage.content with direct use of ResultMessage.result
  • Removed unnecessary imports of AssistantMessage and TextBlock from the main code
  • Added a test file to verify SDK message structure and response handling

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
agent-sdk-server/agent_session.py Simplified response handling by using ResultMessage.result directly; removed handling of AssistantMessage and associated imports
tests/test_sdk_response.py New test file to verify SDK message structure and validate the response format from both AssistantMessage and ResultMessage

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

- handler.py: 删除 `/` 开头命令拦截,支持 Agent Skill 调用
- .gitignore: 移除通配符规则,保留 samconfig.toml.example
@BukeLy
Copy link
Owner Author

BukeLy commented Jan 4, 2026

Code review

Found 1 issue:

  1. Telegram standard commands bypassed to Agent - Removing the command interception logic means /start, /help, and other Telegram standard commands will be sent to the Agent for processing. This causes unnecessary Bedrock API calls and unpredictable Agent behavior for system commands that should be handled at the bot level.

https://github.com/BukeLy/OmniCloud-Ops-Agent/blob/60d074f31d516c3b7e71b78a53e0da64f80605cd/agent-sdk-client/handler.py#L38-L50

Suggestion: Consider filtering standard Telegram commands (/start, /help) while allowing custom skill commands to pass through to the Agent.

🤖 Generated with Claude Code

- If this code review was useful, please react with 👍. Otherwise, react with 👎.

@BukeLy BukeLy merged commit f523246 into main Jan 4, 2026
2 checks passed
@BukeLy BukeLy deleted the fix/use-result-message-for-response branch January 4, 2026 11:45
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