Skip to main content

AFK is the Python SDK for building AI agents that are reliable by default. Define agents with typed contracts, wire in tools and policies, and ship to production with observability, evals, and safety limits built in.

Install

pip install afk
NOTE: You need an LLM provider API key. Set OPENAI_API_KEY, or configure any provider supported by LiteLLM.

Your first agent

from afk.agents import Agent
from afk.core import Runner

agent = Agent(
    name="my-agent",
    model="gpt-5.2-mini",
    instructions="You are a helpful assistant. Be concise and accurate.",
)

runner = Runner()
result = runner.run_sync(agent, user_message="What is an error budget in SRE?")
print(result.final_text)   # ← The agent's response
print(result.state)        # ← "completed"
  1. Agent(...) defines the agent — its name, model, and system prompt instructions. 2. Runner() creates the execution engine with safe defaults (headless mode, in-memory state). 3. run_sync() sends the user message to the LLM, waits for the response, and returns an AgentResult. 4. final_text holds the model’s response. state tells you how the run ended (completed, failed, degraded, or cancelled).

Add a tool in 30 seconds

from pydantic import BaseModel
from afk.agents import Agent
from afk.tools import tool
from afk.core import Runner

class WeatherArgs(BaseModel):
    city: str

@tool(args_model=WeatherArgs, name="get_weather", description="Get current weather for a city.")
def get_weather(args: WeatherArgs) -> dict:
    return {"city": args.city, "temp_f": 72, "condition": "sunny"}

agent = Agent(
    name="weather-bot",
    model="gpt-5.2-mini",
    instructions="Answer weather questions using your tools.",
    tools=[get_weather],           # ← Attach tools here
)

runner = Runner()
result = runner.run_sync(agent, user_message="What's the weather in Austin?")
print(result.final_text)           # ← "It's 72°F and sunny in Austin."

What AFK gives you

How it all fits together

Where to go next