Agent SDK: Teaching Machines to Use Tools with Claude Code

Agent SDK: Teaching Machines to Use Tools with Claude Code

There is a moment in every engineer’s journey when they realize that the most powerful systems are not the ones that do everything themselves—they are the ones that know when to ask for help.

That’s the shift that Claude Code has made mainstream recently: models that don’t just generate text, but reliably use tools to get work done. We’ve been thinking deeply about how to implement this architecture and way of thinking into our own stack.

The Problem with Intelligence

Large language models are remarkably capable. They can reason, plan, and communicate with nuance that surprises even their creators. But ask one to check if a file exists, and you will get a thoughtful explanation of how one might check - not the answer.

The gap between knowing and doing has always been the boundary. Until recently.

Agentic Patterns

Over the past few weeks, our internal tools team has been building systems where AI does not just think—it acts. These are not chatbots with extra steps. They are orchestration layers that treat language models as decision-making cores within larger systems.

If you have used AgentX from Character.ai’s Streams feature, you have seen this in action. What looks like a simple prompt— “create a cinematic video of a samurai cat at sunset”— triggers something far more complex underneath. The AI becomes a film director: planning narrative structure, coordinating image generation with character consistency, orchestrating video synthesis across multiple providers, composing audio tracks, and stitching everything together into a final cut. Thirty autonomous turns. Six specialized tools. Zero human intervention after you hit enter.

The agent does not just call APIs. It thinks in shots and story beats. It knows when to use a Dutch angle versus a rack-focus. It maintains Character consistency across frames so your samurai cat looks the same in every scene.

These patterns emerged from necessity. We needed AI that could participate in workflows, not just comment on them.

Enter the Agent SDK

Anthropic released the Claude Code Agent SDK in Python. It is excellent.

But our backend is Go due to Character.ai’s enormous scale and userbase.

So we built our own port—and in the process, added a few things we needed that did not exist yet.

Code Example (formatted as preformatted text)

agent := claude.NewAPIAgent(claude.APIAgentConfig{
    SystemPrompt: "You are a creative AI assistant.",
    Tools:        tools,
    MaxTurns:     30,
})
events, _ := agent.Run(ctx, userRequest)

The surface is deceptively simple. Underneath, it handles:

  • Tool registration with type-safe generics
  • Streaming events for real-time UI updates
  • Hooks for intercepting and controlling tool execution
  • MCP integration for composable tool ecosystems
  • Direct API agent that bypasses the CLI entirely
  • SSE helpers for HTTP streaming out of the box

This is not just a translation. It is our take on what agentic Go code should feel like—channels for streaming, context for cancellation, interfaces for testing. The patterns that make Go feel like Go.

What Makes This Different

Most agent frameworks treat tools as an afterthought. Register a function, hope the model calls it correctly, parse the response.

We took the opposite approach. Tools are first-class citizens with schemas, typed inputs, and execution hooks that let you:

  • Audit every tool call before it executes
  • Block operations that violate your constraints
  • Modify inputs to inject context or enforce policies
  • Log everything for debugging and compliance

Hook Example (formatted)

hooks.OnTool("Bash").Before(func(ctx context.Context, hc HookContext) HookResult {
    if containsDangerousCommand(hc.Input) {
        return DenyHook("Operation not permitted")
    }
    return AllowHook()
})

This is not about limiting the AI. It is about building systems you can trust in production.

Real Patterns, Real Production

AgentX runs on this SDK. So do other internal tools you have not seen yet.

The generation example in our repository mirrors actual production patterns: parallel asset generation, multi-provider fallbacks, quality control loops that use vision models to verify outputs before proceeding. When a video generation fails, the agent does not crash. It tries the next provider. When quality does not meet thresholds, it regenerates.

Streaming SSE events to frontends, coordinating multi-step workflows, handling the messy reality of async operations across half a dozen AI providers—it is all there because we needed it to be.

The Quiet Part

We are not announcing this with fanfare because the work is not finished. The SDK reflects our current understanding of what agentic systems need, but that understanding evolves weekly.

What we can say: if you are building AI systems in Go that need to do more than generate text, this might save you some time. We have already paid the complexity tax.

Getting Started

Install:

go get github.com/character-ai/claude-agent-sdk-go

The examples directory shows real patterns: streaming responses, custom tools, HTTP servers with SSE, and multi-step generation workflows.

Documentation lives in the README. The code is the best documentation.

Links:

We believe the future of AI is not about building smarter models—it is about building better systems around them. Tools, hooks, and orchestration layers that turn raw intelligence into reliable capability.

This is one small piece of that puzzle.