Skip to content

Add Claude Code AgentRuntime example#377

Open
googs1025 wants to merge 1 commit into
volcano-sh:mainfrom
googs1025:claude-code-agentruntime-example
Open

Add Claude Code AgentRuntime example#377
googs1025 wants to merge 1 commit into
volcano-sh:mainfrom
googs1025:claude-code-agentruntime-example

Conversation

@googs1025
Copy link
Copy Markdown
Member

Adds a small Claude Code SDK example that runs as an AgentRuntime.

Included:

  • FastAPI wrapper around claude-agent-sdk
  • Dockerfile and AgentRuntime manifest
  • curl and AgentCube Python SDK invocation examples

Tested locally with Docker build, kubectl apply --dry-run=client, Router health check, curl invocation, and AgentCube Python SDK invocation.

Copilot AI review requested due to automatic review settings June 4, 2026 23:14
@volcano-sh-bot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign yaozengzeng for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds a new claude-code-agent example that runs a Claude Code SDK loop inside an AgentCube AgentRuntime, including container build/deploy assets and invocation helpers.

Changes:

  • Introduces a FastAPI-based agent server (agent.py) that invokes Claude Code SDK and exposes health/invoke endpoints.
  • Adds Kubernetes AgentRuntime manifest and a Dockerfile to build/run the example in a sandboxed workspace.
  • Adds docs and helper client script for invoking the runtime via AgentCube Router / SDK.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
example/claude-code-agent/requirements.txt Defines Python dependencies for the example server image.
example/claude-code-agent/invoke_with_sdk.py Adds a small client to invoke the deployed AgentRuntime via AgentCube SDK.
example/claude-code-agent/claude-code-agent.yaml Adds a deployable AgentRuntime manifest with environment configuration.
example/claude-code-agent/agent.py Implements the FastAPI server and Claude Code SDK integration.
example/claude-code-agent/README.md Documents build, deploy, and invocation steps for the example.
example/claude-code-agent/Dockerfile Builds the runnable image (Python + Node + Claude Code CLI + server).

Comment on lines +1 to +3
claude-agent-sdk
fastapi>=0.115.0
uvicorn>=0.34.0
Comment on lines +220 to +224
try:
result = _run_sync(run_claude_agent(prompt=prompt, max_turns=max_turns))
except Exception as exc:
return {"error": str(exc)}, 500
return result, 200
Comment on lines +232 to +236
try:
result = await run_claude_agent(prompt=prompt, max_turns=max_turns)
except Exception as exc:
return {"error": str(exc)}, 500
return result, 200
Comment on lines +193 to +196
def _run_sync(value: Any) -> Any:
if inspect.isawaitable(value):
return asyncio.run(value)
return value
Comment on lines +18 to +30
RUN sed -i "s|http://deb.debian.org/debian-security|${APT_SECURITY_MIRROR}|g; s|http://deb.debian.org/debian|${APT_MIRROR}|g" /etc/apt/sources.list.d/debian.sources \
&& apt-get update \
&& apt-get install -y --no-install-recommends ca-certificates curl git xz-utils \
&& rm -rf /var/lib/apt/lists/* \
&& case "${TARGETARCH}" in \
arm64) node_arch="arm64" ;; \
amd64) node_arch="x64" ;; \
*) echo "Unsupported TARGETARCH: ${TARGETARCH}" >&2; exit 1 ;; \
esac \
&& curl -fsSL "${NODE_DIST_BASE}/v${NODE_VERSION}/node-v${NODE_VERSION}-linux-${node_arch}.tar.xz" \
| tar -xJ --strip-components=1 -C /usr/local \
&& npm config set registry "${NPM_REGISTRY}" \
&& npm install -g @anthropic-ai/claude-code
Comment on lines +17 to +18
image: claude-code-agent:latest
imagePullPolicy: IfNotPresent
Comment on lines +23 to +29
client = AgentRuntimeClient(
agent_name=os.getenv("AGENT_NAME", "claude-code-agent"),
router_url=os.getenv("ROUTER_URL", "http://localhost:8081"),
namespace=os.getenv("NAMESPACE", "default"),
session_id=os.getenv("AGENTCUBE_SESSION_ID") or None,
timeout=int(os.getenv("TIMEOUT", "300")),
)
"prompt": os.getenv("PROMPT", "Reply with OK only."),
"max_turns": int(os.getenv("MAX_TURNS", "3")),
},
timeout=int(os.getenv("TIMEOUT", "300")),
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a new example for running a Claude Code SDK agent loop inside an AgentCube AgentRuntime sandbox, including a Dockerfile, deployment manifests, a FastAPI-based agent script, and an SDK invocation script. The feedback highlights several key improvements: correcting the invalid DeepSeek model name (deepseek-v4-flash to deepseek-chat) across the code, configuration, and documentation; using official registries instead of regional mirrors in the Dockerfile for better portability; and defensively parsing and clamping the MAX_TURNS environment variable to prevent potential validation or startup failures.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread example/claude-code-agent/agent.py
Comment thread example/claude-code-agent/claude-code-agent.yaml
Comment thread example/claude-code-agent/Dockerfile
SERVER_HOST = "0.0.0.0"
SERVER_PORT = int(os.environ.get("PORT", "8080"))
WORKSPACE_DIR = os.environ.get("WORKSPACE_DIR", "/workspace")
MAX_TURNS = int(os.environ.get("MAX_TURNS", "10"))
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.

medium

If the MAX_TURNS environment variable is not a valid integer, or if it is configured to be outside the [1, 100] range allowed by the Pydantic schema (InvokeRequest), it can cause startup crashes or validation errors. It is safer to parse and clamp this value defensively.

try:
    MAX_TURNS = max(1, min(100, int(os.environ.get("MAX_TURNS", "10"))))
except ValueError:
    MAX_TURNS = 10

Comment thread example/claude-code-agent/README.md
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Jun 4, 2026

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 57.90%. Comparing base (524e55e) to head (c2f83ea).
⚠️ Report is 119 commits behind head on main.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@             Coverage Diff             @@
##             main     #377       +/-   ##
===========================================
+ Coverage   47.57%   57.90%   +10.33%     
===========================================
  Files          30       34        +4     
  Lines        2819     3181      +362     
===========================================
+ Hits         1341     1842      +501     
+ Misses       1338     1154      -184     
- Partials      140      185       +45     
Flag Coverage Δ
unittests 57.90% <ø> (+10.33%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@googs1025 googs1025 force-pushed the claude-code-agentruntime-example branch 2 times, most recently from e3b94e1 to 5af81c1 Compare June 4, 2026 23:33
Copilot AI review requested due to automatic review settings June 4, 2026 23:36
@googs1025 googs1025 force-pushed the claude-code-agentruntime-example branch from 5af81c1 to 6a16eef Compare June 4, 2026 23:36
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 7 comments.

WORKDIR /app

ARG NODE_VERSION=22.11.0
ARG TARGETARCH
Comment on lines +22 to +26
&& case "${TARGETARCH}" in \
arm64) node_arch="arm64" ;; \
amd64) node_arch="x64" ;; \
*) echo "Unsupported TARGETARCH: ${TARGETARCH}" >&2; exit 1 ;; \
esac \
Comment on lines +35 to +45
def _load_claude_sdk() -> tuple[Callable[..., AsyncIterator[Any]], type]:
try:
from claude_agent_sdk import ClaudeAgentOptions as ClaudeCodeOptions, query
except ImportError as exc:
try:
from claude_code_sdk import ClaudeCodeOptions, query
except ImportError:
raise RuntimeError(
"claude-agent-sdk is not installed. Install requirements.txt or rebuild the example image."
) from exc
return query, ClaudeCodeOptions
Comment on lines +193 to +196
def _run_sync(value: Any) -> Any:
if inspect.isawaitable(value):
return asyncio.run(value)
return value
Comment on lines +222 to +226
try:
result = _run_sync(run_claude_agent(prompt=prompt, max_turns=max_turns))
except Exception as exc:
return {"error": str(exc)}, 500
return result, 200
Comment on lines +234 to +238
try:
result = await run_claude_agent(prompt=prompt, max_turns=max_turns)
except Exception as exc:
return {"error": str(exc)}, 500
return result, 200
Comment on lines +1 to +3
claude-agent-sdk
fastapi>=0.115.0
uvicorn>=0.34.0
Signed-off-by: CYJiang <googs1025@gmail.com>
@googs1025 googs1025 force-pushed the claude-code-agentruntime-example branch from 6a16eef to c2f83ea Compare June 4, 2026 23:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants