Skip to content

Anthropic interleaved/extended thinking isn't captured properly by the default Anthropic instrumentation #1737

@ldorigo

Description

@ldorigo

Description

(C.f. discussion on Logfire's slack: https://pydanticlogfire.slack.com/archives/C06EDRBSAH3/p1771351911189739 )

Image

The code looks like:

# Build request kwargs with thinking enabled
            kwargs: dict[str, Any] = {
                "model": self.model_name_map[self.model_params.model_version],
                "messages": anthropic_messages,
                "temperature": 1,  # Only temperature of 1 is supported for thinking
                "max_tokens": self._resolve_max_tokens(default_max_tokens=16384),
                "stream": True,
                "tools": anthropic_tools,
            }

            if system_message:
                kwargs["system"] = system_message

            # Add thinking parameter if budget specified
            if thinking_budget is not None:
                kwargs["thinking"] = {"type": "enabled", "budget_tokens": thinking_budget}

            # Call Anthropic API with beta features for interleaved thinking
            logger.debug(f"Starting agentic loop iteration {iteration_num}")
            stream = await self.client.beta.messages.create(
                betas=["interleaved-thinking-2025-05-14"], **kwargs
            )

Outputs aren't shown and instead the 'tool results' (user message sent back with tool results) are shown as outputs.

Python, Logfire & OS Versions, related packages (not required)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions