Skip to content

Conversation

siwachabhi
Copy link
Contributor

@siwachabhi siwachabhi commented Sep 7, 2025

  • Improve cli panels and log stream
  • Improve utf-8 handling
(bedrock-agentcore-starter-toolkit) ➜  bedrock-agentcore-starter-toolkit git:(main) ✗ uv run agentcore invoke "tell me a japanese joke with emoji and kanji"
╭─────────────────────────────────────────────────────────────────── test_siwabhi_9_6_3 ────────────────────────────────────────────────────────────────────╮
│ Session: e8b4b745-4e86-4302-addf-71585fc201bb                                                                                                             │
│ Request ID: 565ff74d-02d1-4dee-82f7-a0431dae5a70                                                                                                          │
│ ARN: arn:aws:bedrock-agentcore:us-west-2:309149493152:runtime/test_siwabhi_9_6_3-XKlbkFFkJZ                                                               │
│ Logs: aws logs tail /aws/bedrock-agentcore/runtimes/test_siwabhi_9_6_3-XKlbkFFkJZ-DEFAULT --log-stream-name-prefix "2025/09/07/[runtime-logs]" --follow   │
│       aws logs tail /aws/bedrock-agentcore/runtimes/test_siwabhi_9_6_3-XKlbkFFkJZ-DEFAULT --log-stream-name-prefix "2025/09/07/[runtime-logs]" --since 1h │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

Response:
Here's a classic Japanese pun joke! 😄

**布団が吹っ飛んだ!** 🛏️💨
(Futon ga futtonda!)

Translation: "The futon got blown away!"

The joke is a play on words (dajare/駄洒落):
- 布団 (futon) = Japanese bedding/mattress
- 吹っ飛んだ (futtonda) = got blown away

It's funny because "futon" and "futton(da)" sound very similar! 😂

Japanese people love these simple wordplay jokes, even though they often make people groan! 🤭

With a syntax error in code

(bedrock-agentcore-starter-toolkit) ➜  bedrock-agentcore-starter-toolkit git:(chore/improve_invoke) ✗ uv run agentcore invoke "tell me a japanese joke with emoji and kanji"
╭─────────────────────────────────────────────────────────────────── test_siwabhi_9_6_3 ────────────────────────────────────────────────────────────────────╮
│ Session: b8d0bba8-4dd7-475b-b40d-892943c33ed9                                                                                                             │
│ Request ID: 84be6744-a140-4320-b8ea-fc2f71583bdf                                                                                                          │
│ ARN: arn:aws:bedrock-agentcore:us-west-2:309149493152:runtime/test_siwabhi_9_6_3-XKlbkFFkJZ                                                               │
│ Logs: aws logs tail /aws/bedrock-agentcore/runtimes/test_siwabhi_9_6_3-XKlbkFFkJZ-DEFAULT --log-stream-name-prefix "2025/09/07/[runtime-logs]" --follow   │
│       aws logs tail /aws/bedrock-agentcore/runtimes/test_siwabhi_9_6_3-XKlbkFFkJZ-DEFAULT --log-stream-name-prefix "2025/09/07/[runtime-logs]" --since 1h │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

Invocation failed: An error occurred (RuntimeClientError) when calling the InvokeAgentRuntime operation: An error occurred when starting the runtime. Please
check your CloudWatch logs for more information.

Overview

This PR significantly improves the agentcore invoke command user experience with consistent panel layouts, better error handling, and enhanced
CloudWatch log integration. Additionally, it includes UTF-8 handling improvements and CloudWatch log formatting fixes.

✨ Key Improvements

🎨 Consistent CLI Panel Experience

  • Unified Info Panels: Standardized panel format showing Session ID, Request ID, Agent ARN, and CloudWatch logs for both success and error scenarios
  • Ready-to-Copy Log Commands: Direct AWS CLI tailing commands in panels for immediate debugging
  • Visual Consistency: Consistent styling across all invoke scenarios with proper error/success separation

🔧 Enhanced Error Handling

  • Consistent Error Display: Unified error experience with debugging context and next steps
  • Better Context: Error panels now include relevant debugging information (CloudWatch logs, suggested commands)
  • Graceful Fallbacks: Robust error handling for missing configurations and deployment states

📊 Improved Response Processing

📝 CloudWatch Log Improvements

  • Single-Line Logs: Added ⟪NEWLINE⟫ markers in SDK to prevent multi-line log entries from splitting across CloudWatch entries
  • Visible Line Breaks: Newlines in log messages now show as clear visual markers instead of causing fragmented log entries
  • Better Debugging: More coherent log reading experience for multi-line agent responses

🛠 Technical Changes

Service Layer (runtime.py)

CLI Layer (commands.py)

  • Added helper functions: _show_invoke_info_panel, _show_success_response, _show_error_response
  • Standardized panel content across all invoke scenarios
  • Improved multi-part response handling with proper list joining
  • Enhanced error context with CloudWatch log commands

SDK Integration

  • Modified RequestContextFormatter in bedrock-agentcore-sdk-python to replace newlines with ⟪NEWLINE⟫ markers
  • Prevents CloudWatch log entry fragmentation for multi-line responses
  • Benefits both CLI and notebook users

Testing & Quality

  • Added comprehensive test coverage for new response parsing scenarios
  • Updated test expectations to match new consistent panel formats
  • Fixed all linting issues and achieved 90%+ code coverage
  • All pre-commit checks passing

📸 Before & After

Before:

Session ID: abc-123
ARN: arn:aws:bedrock... # dim/inconsistent styling
Payload: {...} # verbose raw output

Error scenarios had different formats

CloudWatch logs showed fragmented multi-line entries

After:

╭─────────────────── agent_name ───────────────────╮
│ Session: abc-123 │
│ Request ID: req-456 │
│ ARN: arn:aws:bedrock... │
│ Logs: aws logs tail ... --follow │
│ aws logs tail ... --since 1h │
╰──────────────────────────────────────────────────╯

Response:
Clean, properly formatted response content

🎯 Impact

  • Developer Experience: Faster debugging with ready-to-copy log commands
  • Consistency: Unified experience across success/error scenarios
  • Debugging: Better CloudWatch log readability with single-line entries
  • Maintainability: Cleaner, more concise codebase with comprehensive test coverage

🧪 Testing

  • All existing tests pass
  • New test coverage for multi-part response scenarios
  • Manual testing across success/error flows
  • Pre-commit hooks and coverage requirements met

- Change agent to use payload.get('prompt') instead of payload.get('message')
- Update invoke command to send proper JSON with 'prompt' field
- Should resolve ValidationException about conversation needing user message
)
agent_display = config.name if config else (agent or "unknown")
_show_invoke_info_panel(agent_display, result, config)
if result.response:
Copy link
Contributor

Choose a reason for hiding this comment

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

tested the changes - panel improvements look great but response was still showing in old json format.. looks like the extraction doesn't account for the full AWS API response structure that includes the ResponseMetaData. Following is the change that got it working for me. Please review.
`

    if result.response != {}:
        content = result.response

        # Extract from AWS response structure if present
        if isinstance(content, dict) and "response" in content:
            content = content.get("response")
        
        # Handle list responses
        if isinstance(content, list) and len(content) > 0:
            content = content[0]
        
        # Parse JSON string if needed
        if isinstance(content, str):
            try:
                parsed = json.loads(content)
                if isinstance(parsed, dict) and "response" in parsed:
                    content = parsed["response"]
            except (json.JSONDecodeError, TypeError):
                pass
        
        console.print("[bold]Response:[/bold]")
        console.print(content)

`

@siwachabhi siwachabhi merged commit 824b22c into main Sep 8, 2025
16 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