Skip to content

fix(cartesia-sdk): avoid retrying wrapped agent#1275

Open
GautamSharma99 wants to merge 1 commit into
supermemoryai:mainfrom
GautamSharma99:fix/cartesia-single-agent-execution
Open

fix(cartesia-sdk): avoid retrying wrapped agent#1275
GautamSharma99 wants to merge 1 commit into
supermemoryai:mainfrom
GautamSharma99:fix/cartesia-single-agent-execution

Conversation

@GautamSharma99

Copy link
Copy Markdown
Contributor

Summary

The Cartesia wrapper previously enclosed memory preparation and the entire
wrapped-agent stream in one broad try/except.

If the wrapped agent failed—even after yielding output—the exception handler
invoked it again from the beginning. This could duplicate spoken output, tool
calls, messages, payments, or other non-idempotent actions.

This PR:

  • extracts best-effort user-turn preparation from agent execution
  • limits fallback handling to memory enrichment and persistence preparation
  • invokes the wrapped agent exactly once per event
  • allows wrapped-agent exceptions to propagate normally
  • preserves graceful fallback when memory preparation fails

Behavioral change

Before:

  1. The wrapped agent could yield output or perform side effects.
  2. The wrapped agent raised an exception.
  3. The wrapper caught the exception and restarted the agent.

After:

  1. Memory preparation runs with graceful fallback.
  2. The wrapped agent runs exactly once.
  3. Any wrapped-agent failure propagates without replaying the turn.

Tests

Added regression coverage for:

  • failure after partial output
  • failure before the first output
  • memory-preparation failure falling back to one agent call

Validation completed:

  • Cartesia package tests with real dependencies: 4 passing
  • isort: passing
  • mypy: passing after suppressing Cartesia Line’s missing py.typed marker
  • new test files pass Black formatting

The existing agent.py file is not fully Black-formatted on main; this PR
avoids unrelated whole-file formatting changes. The repository-wide Bun suite
also retains unrelated existing failures.

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