Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 26 additions & 11 deletions components/runners/ambient-runner/ag_ui_claude_sdk/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class ClaudeAgentAdapter:
Forwarded Props Support:
Per-run overrides for execution control without changing agent identity.
Whitelisted keys include: resume, fork_session, model, temperature, max_tokens,
max_thinking_tokens, max_turns, max_budget_usd, output_format, etc.
thinking, max_thinking_tokens, max_turns, max_budget_usd, output_format, etc.

Example:
RunAgentInput(
Expand Down Expand Up @@ -770,12 +770,16 @@ def flush_pending_msg():
current_reasoning_id = str(uuid.uuid4())
ts = now_ms()
yield ReasoningStartEvent(
threadId=thread_id, runId=run_id,
messageId=current_reasoning_id, timestamp=ts,
threadId=thread_id,
runId=run_id,
messageId=current_reasoning_id,
timestamp=ts,
)
yield ReasoningMessageStartEvent(
threadId=thread_id, runId=run_id,
messageId=current_reasoning_id, timestamp=ts,
threadId=thread_id,
runId=run_id,
messageId=current_reasoning_id,
timestamp=ts,
)
elif block_type == "tool_use":
# Tool call starting - emit TOOL_CALL_START
Expand Down Expand Up @@ -807,12 +811,16 @@ def flush_pending_msg():
in_thinking_block = False
ts = now_ms()
yield ReasoningMessageEndEvent(
threadId=thread_id, runId=run_id,
messageId=current_reasoning_id, timestamp=ts,
threadId=thread_id,
runId=run_id,
messageId=current_reasoning_id,
timestamp=ts,
)
yield ReasoningEndEvent(
threadId=thread_id, runId=run_id,
messageId=current_reasoning_id, timestamp=ts,
threadId=thread_id,
runId=run_id,
messageId=current_reasoning_id,
timestamp=ts,
)

# Persist thinking content as ReasoningMessage per AG-UI spec.
Expand Down Expand Up @@ -1124,12 +1132,19 @@ def flush_pending_msg():
logger.debug("Cleanup: closing hanging thinking block")
ts = now_ms()
yield ReasoningMessageEndEvent(
threadId=thread_id, runId=run_id, timestamp=ts
threadId=thread_id,
runId=run_id,
messageId=current_reasoning_id,
timestamp=ts,
)
yield ReasoningEndEvent(
threadId=thread_id, runId=run_id, timestamp=ts
threadId=thread_id,
runId=run_id,
messageId=current_reasoning_id,
timestamp=ts,
)
in_thinking_block = False
current_reasoning_id = None

if has_streamed_text and current_message_id:
logger.debug(
Expand Down
3 changes: 2 additions & 1 deletion components/runners/ambient-runner/ag_ui_claude_sdk/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"fallback_model", # Fallback if primary fails
"temperature", # Sampling temperature
"max_tokens", # Response length limit
"max_thinking_tokens", # Reasoning depth limit
"max_thinking_tokens", # Reasoning depth limit (legacy, prefer thinking)
"thinking", # Thinking config: {"type": "adaptive"} | {"type": "enabled", "budget_tokens": N} | {"type": "disabled"}
"max_turns", # Conversation turn limit
"max_budget_usd", # Cost limit per run
# Output control
Expand Down
16 changes: 16 additions & 0 deletions components/runners/ambient-runner/ag_ui_claude_sdk/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,22 @@ def apply_forwarded_props(
if not forwarded_props or not isinstance(forwarded_props, dict):
return merged_kwargs

# Migrate deprecated max_thinking_tokens → thinking config
if (
"max_thinking_tokens" in forwarded_props
and "thinking" not in forwarded_props
and forwarded_props["max_thinking_tokens"] is not None
):
from claude_agent_sdk.types import ThinkingConfigEnabled

budget = forwarded_props.pop("max_thinking_tokens")
forwarded_props["thinking"] = ThinkingConfigEnabled(budget_tokens=budget)
logger.warning(
"max_thinking_tokens is deprecated; converted to "
"thinking=ThinkingConfigEnabled(budget_tokens=%d)",
budget,
)

applied_count = 0
for key, value in forwarded_props.items():
# Only apply whitelisted keys
Expand Down
4 changes: 2 additions & 2 deletions components/runners/ambient-runner/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ dependencies = [

[project.optional-dependencies]
claude = [
"anthropic[vertex]>=0.68.0",
"claude-agent-sdk>=0.1.23",
"anthropic[vertex]>=0.86.0",
"claude-agent-sdk>=0.1.50",
Comment on lines +23 to +24

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== 1) Find deprecated option usage =="
rg -n -C2 '\bmax_thinking_tokens\b' -g '!**/tests/**' || true

echo
echo "== 2) Find new thinking config usage/imports =="
rg -n -C2 '\bThinkingConfig(Adaptive|Enabled|Disabled)\b|\bthinking\s*=' -g '!**/tests/**' || true

echo
echo "== 3) Find claude-agent-sdk callsites/options objects for manual inspection =="
rg -n -C3 'ClaudeAgentOptions|claude-agent-sdk|create_session|session|thinking' components/runners/ambient-runner || true

Repository: ambient-code/platform

Length of output: 50378


Migrate max_thinking_tokens to thinking config before merging claude-agent-sdk>=0.1.50.

The codebase still references the deprecated max_thinking_tokens parameter in ag_ui_claude_sdk/config.py (line 19) and ag_ui_claude_sdk/adapter.py (line 140), but the SDK version bump to >=0.1.50 removes support for this option. Update all usages to the new thinking + ThinkingConfig* pattern to prevent startup errors or runtime incompatibility.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@components/runners/ambient-runner/pyproject.toml` around lines 23 - 24, The
code still uses the deprecated max_thinking_tokens option; change all usages to
the new thinking config pattern (ThinkingConfig or ThinkingConfig*) before
bumping claude-agent-sdk to >=0.1.50: in ag_ui_claude_sdk.config (where
max_thinking_tokens is defined/loaded) replace that field with a thinking object
built from the SDK's ThinkingConfig* type, and in ag_ui_claude_sdk.adapter
(where max_thinking_tokens is passed, e.g., at the call site around line 140)
construct and pass the corresponding thinking=ThinkingConfig(...) instance
instead of max_thinking_tokens; ensure imports for the SDK ThinkingConfig type
are added/updated and any tests or defaults are adjusted to the new structure so
runtime startup uses thinking consistently.

]
observability = [
"langfuse>=3.0.0",
Expand Down
23 changes: 12 additions & 11 deletions components/runners/ambient-runner/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading