1:1 Mentoring with Big Tech AI Engineers
LLM & Agentic

Agent SDK Patterns

Building production agents with the Claude Agent SDK.

Pattern: Tool Registry

class ToolRegistry:
    def __init__(self):
        self._tools = {}

    def register(self, name, description, schema):
        def deco(fn):
            self._tools[name] = {
                "description": description,
                "schema": schema, "fn": fn
            }
            return fn
        return deco

    def schemas(self):
        return [{"name": n, "description": t["description"],
                 "input_schema": t["schema"]}
                for n, t in self._tools.items()]

    def call(self, name, args):
        return self._tools[name]["fn"](**args)

tools = ToolRegistry()

@tools.register("get_weather", "Get weather for a city",
    {"type": "object", "properties": {"city": {"type": "string"}}})
def _(city):
    return {"temp": 24, "condition": "sunny"}

Pattern: Retry with Backoff

import time, functools, random

def retry(times=3, base=0.5):
    def deco(fn):
        @functools.wraps(fn)
        def wrapper(*a, **kw):
            for attempt in range(times):
                try: return fn(*a, **kw)
                except Exception:
                    if attempt == times - 1: raise
                    time.sleep(base * 2**attempt + random.uniform(0, 0.1))
        return wrapper
    return deco

@retry(times=4)
def call_claude(prompt): ...

More in LLM & Agentic

Get full access to all 87 sections with code examples, diagrams, and interactive animations.

Sign Up Free