แก้ไข

Anthropic Claude

agent-framework-claude wraps the Claude Agent SDK as ClaudeAgent. It uses Claude's managed agent runtime, sessions, permission model, built-in tools, and MCP support while exposing the Agent Framework run and streaming interfaces.

This integration is distinct from the Anthropic model provider, which uses Claude as the model behind an application-owned Agent Framework agent.

Prerequisites

  • Install and configure the Claude Code CLI.
  • Choose a Claude model and permission mode.
  • Run the agent in a constrained working directory when enabling file or shell tools.

Install the package

pip install agent-framework-claude --pre

Configuration

Variable Purpose
CLAUDE_AGENT_MODEL Claude model used by the managed runtime.
CLAUDE_AGENT_PERMISSION_MODE Default permission mode for built-in and MCP tools.
CLAUDE_AGENT_CLI_PATH Optional explicit path to the Claude Code CLI.
CLAUDE_AGENT_CWD Working directory exposed to the runtime.
CLAUDE_AGENT_MAX_TURNS Optional maximum number of agent turns.
CLAUDE_AGENT_MAX_BUDGET_USD Optional cost budget for a run.

Create a ClaudeAgent

ClaudeAgent supports regular and streaming runs and can expose Agent Framework function tools.

async def non_streaming_example() -> None:
    """Example of non-streaming response."""
    print("=== Non-streaming Example ===")

    agent = ClaudeAgent(
        name="BasicAgent",
        instructions="You are a helpful assistant. Keep responses concise.",
        tools=[get_weather],
    )

    async with agent:
        query = "What's the weather in Seattle?"
        print(f"User: {query}")
        result = await agent.run(query)
        print(f"Agent: {result.text}\n")


async def streaming_example() -> None:
    """Example of streaming response."""
    print("=== Streaming Example ===")

    agent = ClaudeAgent(
        name="StreamingAgent",
        instructions="You are a helpful assistant.",
        tools=[get_weather],
    )

    async with agent:
        query = "What's the weather in Paris?"
        print(f"User: {query}")
        print("Agent: ", end="", flush=True)
        async for chunk in agent.run(query, stream=True):
            if chunk.text:
                print(chunk.text, end="", flush=True)
        print("\n")

Additional samples demonstrate:

  • Claude built-in file and shell tools.
  • Interactive permission handling.
  • Local and remote MCP servers.
  • Session persistence and resumption.
  • Sequential workflows that pass prior messages between Claude agents.
  • URL fetching and multiple permission rules.

When ClaudeAgent receives multiple messages, it sends one prompt that frames them as conversation history and labels each message by role. This approach preserves role boundaries during agent handoffs, but it doesn't replay native Claude multi-role history or share a Claude session. A single user message remains unchanged.

Permission considerations

  • Start with the least-permissive Claude Agent SDK permission mode that supports the task.
  • Require explicit approval for shell, file, network, or other side-effecting operations.
  • Don't expose credentials through environment variables or readable files in the agent working directory.

Next steps