Skip to content

fix: prevent re-entrant agent.step() in ScreenshotToolkit.read_image#3911

Open
atian8179 wants to merge 2 commits intocamel-ai:masterfrom
atian8179:fix/screenshot-toolkit-reentrant-step
Open

fix: prevent re-entrant agent.step() in ScreenshotToolkit.read_image#3911
atian8179 wants to merge 2 commits intocamel-ai:masterfrom
atian8179:fix/screenshot-toolkit-reentrant-step

Conversation

@atian8179
Copy link
Copy Markdown

Problem

ScreenshotToolkit.read_image() calls self.agent.step() to analyze images. When this tool is invoked by the same agent, it creates a re-entrant step() call during tool execution, corrupting the tool-call message sequence:

400 Bad Request: An assistant message with 'tool_calls' must be followed by
tool messages responding to each 'tool_call_id'...

Solution

Replace self.agent.step() with a separate lightweight ChatAgent instance that uses the same model backend. This avoids re-entrancy while preserving image analysis capability.

Fixes #3869

Langfuse v3 removed langfuse.decorators.langfuse_context, causing
NameError when configuring tracing. Update to detect Langfuse version
and use environment variables for v3+ (which @observe() reads
automatically) while maintaining backward compatibility with v2.

Fixes camel-ai#3876
ScreenshotToolkit.read_image() called self.agent.step() to analyze
images, creating a re-entrant step() call when the tool is invoked
by the same agent. This corrupts the tool-call message sequence,
causing 400 errors from the API.

Replace with a lightweight separate ChatAgent instance using the
same model backend, avoiding re-entrancy while preserving the
image analysis capability.

Fixes camel-ai#3869
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 6, 2026

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 59639299-e6d5-4879-b090-56514c17ea8b

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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.

[BUG] ScreenshotToolkit.read_image re-enters current agent and breaks tool-call chain

1 participant