Skip to content

fix: fix Agent printing#513

Merged
DoganK01 merged 2 commits intomasterfrom
printing-fix
Jan 29, 2026
Merged

fix: fix Agent printing#513
DoganK01 merged 2 commits intomasterfrom
printing-fix

Conversation

@DoganK01
Copy link
Copy Markdown
Member

  • make "print" flag true as default

@claude
Copy link
Copy Markdown

claude bot commented Jan 29, 2026

PR Review: Fix Agent Printing (#513)

Summary

This PR changes the default value of the print flag from False to True for both Agent and Direct classes, and ensures print settings propagate consistently throughout the framework.


✅ Positive Aspects

  1. Consistency improvements: The print flag now properly propagates to the CultureManager and is checked consistently across pipeline steps.

  2. Better UX by default: Making printing default to True provides a better out-of-box experience for new users who want to see agent output without having to know about the print flag.

  3. Improved robustness: Added null checks (agent and hasattr(agent, 'print')) in multiple places to prevent potential AttributeErrors.

  4. Serialization support: The CultureManager now properly serializes/deserializes print settings in to_dict() and from_dict().


⚠️ Issues and Concerns

1. Breaking Change Without Migration Path

Severity: High

This is a breaking change that will affect all existing code:

  • Users who rely on the default silent behavior (print=False) will now see output they didn't expect
  • No deprecation warning or migration guide is provided
  • The PR description doesn't mention this is a breaking change

Recommendation:

  • Add a prominent note in the changelog/release notes about this breaking change
  • Consider a transition period with a deprecation warning
  • Document the change in migration guide

Files affected: src/upsonic/agent/agent.py:271, src/upsonic/direct.py:69

2. Inconsistent API Change in chat.py

Severity: Medium
Location: src/upsonic/chat/chat.py:709

# Changed from:
result = await self.agent.print_do_async(task, debug=self.debug, **kwargs)
# To:
result = await self.agent.do_async(task, debug=self.debug, **kwargs)

Issues:

  • This suggests print_do_async() existed and is being removed, but there's no context about this method
  • If print_do_async() was a separate method, removing it is a breaking API change
  • The change implies the default print behavior now handles what print_do_async() previously did

Recommendation:

  • If print_do_async() was deprecated, ensure it's marked as such and still available
  • Document what print_do_async() did and why it's no longer needed
  • Add a test to ensure chat printing behavior works as expected

3. Missing Test Coverage

Severity: High

The PR modifies critical behavior but doesn't include any tests to verify:

  • Default print flag values are correctly set
  • Print flag properly propagates to CultureManager
  • Print suppression works when print=False
  • The new conditional logic in print_price_id_summary() works correctly
  • Culture manager serialization/deserialization preserves print settings

Recommendation: Add tests covering:

# Test default print values
def test_agent_default_print_flag():
    agent = Agent(name="test", model="openai/gpt-4o-mini")
    assert agent.print == True

# Test print flag propagation
def test_print_flag_propagates_to_culture():
    agent = Agent(name="test", model="openai/gpt-4o-mini", 
                  culture="helpful", print=False)
    assert agent._culture_manager.print == False

# Test print suppression
def test_price_summary_respects_print_flag():
    # Verify print_price_id_summary doesn't print when print_output=False
    ...

4. Potential Logic Issue in print_price_id_summary()

Severity: Low
Location: src/upsonic/utils/printing.py:1275-1281

The new early return logic may not handle all cases correctly:

if not print_output:
    if price_id in price_id_summary:
        summary = price_id_summary[price_id].copy()
        summary['estimated_cost'] = f"${summary['estimated_cost']:.4f}"
        return summary
    return None

When print_output=True, the function continues and later checks if price_id not in price_id_summary (line 1286), printing an error. However, when print_output=False and the price_id is missing, it silently returns None without any indication of the error.

Recommendation: Consider consistent error handling regardless of print_output setting, or document this intentional behavior difference.

5. Incomplete Propagation Check

Severity: Low
Location: src/upsonic/agent/pipeline/steps.py:2884

print_output = agent.print if agent and hasattr(agent, 'print') else False
print_price_id_summary(task.price_id, task, print_output=print_output)

This defaults to False when agent is None or doesn't have print attribute. However, given the new default is True, shouldn't this also default to True for consistency?

Recommendation: Consider changing to:

print_output = agent.print if agent and hasattr(agent, 'print') else True

🔒 Security Considerations

No security issues identified. The changes only affect console output visibility.


⚡ Performance Considerations

Minor Impact: Enabling printing by default will have a small performance overhead for users who don't need output, as string formatting and console I/O will occur. However, this is negligible for most use cases.


📝 Code Quality

Good:

  • Consistent code style
  • Defensive programming with null checks
  • Proper parameter documentation

Needs improvement:

  • Missing inline comments explaining the rationale for the default change
  • The version bump (0.71.1 → 0.71.2) suggests a patch, but this is arguably a minor version change due to behavior modification

🎯 Recommendations

  1. Critical: Add comprehensive tests for the new default behavior
  2. Critical: Document this as a breaking change in release notes
  3. High: Clarify the print_do_async() removal in chat.py
  4. Medium: Review default fallback value in pipeline step 2884
  5. Medium: Add migration guide for users expecting silent behavior
  6. Low: Consider consistency in error handling for print_price_id_summary()

✅ Approval Recommendation

Request Changes - The PR needs tests and documentation before merging. The core implementation looks solid, but the lack of test coverage and the undocumented breaking change are blockers.

Once tests are added and the breaking change is properly documented, this should be good to merge.

@claude
Copy link
Copy Markdown

claude bot commented Jan 29, 2026

PR Review: Fix Agent Printing (#513)

This PR changes the default print flag from False to True for Agent and Direct classes.

Positive Aspects

  1. Consistency improvements - The print flag now properly propagates to CultureManager
  2. Better UX by default - New users see agent output without configuration
  3. Improved robustness - Added null checks to prevent AttributeErrors
  4. Serialization support - CultureManager properly handles print settings

Issues and Concerns

1. Breaking Change Without Migration Path (Severity: High)

This is a breaking change affecting all existing code. Users relying on silent behavior will now see unexpected output. No deprecation warning or migration guide provided.

Recommendation: Add changelog notes and migration guide for this breaking change.

Files affected: src/upsonic/agent/agent.py:271, src/upsonic/direct.py:69

2. API Change in chat.py (Severity: Medium)

Changed from print_do_async() to do_async() at src/upsonic/chat/chat.py:709. This may be a breaking API change if print_do_async() was a public method.

Recommendation: Document what print_do_async() did and ensure backward compatibility or deprecation path.

3. Missing Test Coverage (Severity: High)

No tests verify: default print flag values, propagation to CultureManager, print suppression, print_price_id_summary() conditional logic, or culture manager serialization.

Recommendation: Add comprehensive tests for new default behavior.

4. Logic Issue in print_price_id_summary() (Severity: Low)

Inconsistent error handling - prints error when print_output=True and price_id missing, but silently returns None when print_output=False.

5. Incomplete Propagation (Severity: Low)

At src/upsonic/agent/pipeline/steps.py:2884, defaults to False when agent is None. Should this default to True for consistency?

Security & Performance

No security issues. Minor performance overhead from enabled printing, but negligible.

Recommendations

  1. CRITICAL: Add comprehensive tests
  2. CRITICAL: Document as breaking change in release notes
  3. HIGH: Clarify print_do_async() removal
  4. MEDIUM: Review default fallback values for consistency
  5. MEDIUM: Add migration guide

Approval: Request Changes

The core implementation is solid, but needs tests and documentation before merging.

@DoganK01 DoganK01 merged commit 4af4717 into master Jan 29, 2026
5 checks passed
@DoganK01 DoganK01 deleted the printing-fix branch January 29, 2026 15:05
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