Get started
Concepts
The words you need to navigate the rest of these docs without flinching.
8 min read
AgentGraft has a small vocabulary. Read this page once and the rest of the docs will make sense without you having to keep a glossary open. Every term here corresponds to a database row, a decorator or a setting — there are no abstract concepts you can't grep for.
#The mental model in one sentence
A Workspace owns one or more Grafts; each Graft is a single chat-widget integration; each Graft has its own Tools, Agents, and prompt content; the host app declares all of that in code via a named Profile and pushes it with one sync command.
#Workspace
Workspaces are the multi-tenant boundary. A user with a membership in workspace A cannot see grafts, conversations, or members of workspace B unless they're also a member there. Switching workspaces in the dashboard is a navigation action, not a login — your identity stays the same, only the scope changes.
#Graft
The metaphor is botanical. A graft is grown on a host (your Django app) and bears its fruit (the chat experience) on that host's surface. The hosted runtime provides the scaffolding but the integration belongs to your codebase.
#Profile
AGENTGRAFT['profiles'] settings dict that maps to one graft's credentials. Profile names are arbitrary strings — default, marketing, admin. Every decorator (@ag.tool, @ag.agent) takes an optional profile= keyword that pins it to a specific profile's registry.If your host app only has one chat experience, the default profile is the only one you need. Multi-profile setups become useful when you have, say, a marketing chat for anonymous visitors AND an in-app helper for authenticated users — same Python file, two completely separated tool registries, two separated grafts on the server.
#Tool
@ag.tool. Takes the resolved user object as its first argument; type hints on subsequent arguments are auto-converted to a JSON schema the LLM consumes. The function runs inside your host app's process — AgentGraft's runtime hits your webhook, the SDK dispatches to the matching function, the return value is JSON-serialised back to the LLM.@ag.tool
def get_dataset(user: User, dataset_id: int) -> dict:
"""Get one dataset's metadata by id."""
ds = Dataset.objects.get(pk=dataset_id, owner=user)
return {"id": ds.id, "name": ds.name, "rows": ds.row_count}
#Agent
@ag.agent. Mark one agent entry=True: it answers a new conversation until it hands off, and the conversation stays with whichever agent it reached. Your server may start a conversation on another agent instead. Sync accepts a graft without an entry point, but its chats then fail. Optionally, one other agent is private: it answers the widget's incognito chat, which is not saved.Agents are how you compose complex chat experiences without writing one giant system prompt. A typical setup has a small router agent that triages incoming messages, plus a handful of specialist agents (one for billing questions, one for data lookups, one for documentation search) that the router hands off to as needed.
#Policy
ag.policy("agentgraft/no-hallucination") and the sync command fetches the body from the Policy Shop and substitutes it into your graft's prompt at sync time. Policies cover common needs like 'never invent values', 'cite sources', 'use markdown for emphasis', 'redact secrets'.Policies are an optional convenience — you can write any text directly into the policies=[...] list on your graft. The Policy Shop just saves you from copy-pasting the same five rules into every project.
#User identity
@ag.user_loader. Whatever you return becomes the first argument to every tool function in that profile.AgentGraft never reads your database or your user records. It knows each visitor only by the external id you chose, and keeps that visitor's conversations, memories and display name under it. Your server signs the id with the graft's webhook secret when it renders the page; the widget sends that signature with every request, AgentGraft verifies it, and your user_loader does the actual lookup when a tool runs.
user:<pk> for your users, a session: id for a logged-out browser, any id you choose for a bot. Visitors are per graft, and each has their own conversations, memory and allowance.#Kinds of agent
entry=True. It answers a new conversation, and the conversation stays with whichever agent it reaches. At most one per graft.handoffs=[...] passes the whole conversation to another agent, which answers from then on. sub_agents=[...] calls another agent like a tool: it runs its own tools and returns an answer, and the caller stays in charge.model= (a Cailos codename, auto by default, such as auto:speed), so a router can be cheap and a specialist strong.private=True. It answers the widget's incognito chat, which AgentGraft doesn't save and which gets no memory. It can't be the entry point, hand off, call sub-agents or be unattended. Its tool calls still reach your app, marked private.unattended=True answers with no person reading along: a bot your server runs. Its replies get no suggested follow-ups or auto-title, and its conversations no Reflector questions; long-term memory still works.identity= on an agent replaces the graft's identity in that agent's prompt only; voice, scope, policies and references still apply.memory=False keeps an agent out of the visitor's long-term memory: no memory tools or memories in its prompt, and its turns teach the memory nothing. Its conversations are still saved. Sync refuses a handoff or sub-agent between agents with memory on and off.#Memory and long conversations
memory_enabled=True, a visitor's memory is a graph of facts about them, shared by the graft's agents. After each turn (batched over a couple of minutes) the Dreamer reads what's new and adds, updates, links or retires facts. Each turn, the facts that matter most are placed in the prompt, and agents can call recall_memories to search more and manage_memories when the visitor says "remember" or "forget". The Reflector picks questions worth asking the visitor later. Facts fade unless they come up again; a fact the visitor wrote, edited or asked an agent to remember is theirs, and the Dreamer leaves it alone. Off on a new graft.recap_enabled=True, a conversation idle for recap_min_gap_minutes (at least 30) gets a short "where you left off" note, waiting when the visitor returns and gone once they send a message.#Spend and server calls
visitor_quota_usd (default $5.00) in a rolling visitor_quota_window_days (default 7). Past it, chat answers 429. Spend is kept on an append-only ledger, so deleting threads gives none back. Your server can point a visitor at another's allowance (spend_as), so a user and all their bots share one pool; pools don't chain.X-AgentGraft-Server-Key) is your server, not a page. Only it may start a conversation on a chosen agent, add a turn's instructions or set spend_as; a page asking gets a 403, and a wrong key a 401.turn_key makes a retried send safe: the turn runs once, and sending again returns its reply. budget_s (at most 480 s) gives a turn no one watches a deadline: its tools close then, it has reply_s (30 s by default, at most 60) to reply, and a reply cut off says cut_short. Each tool call carries its turn's key and conversation id.#How they fit together
Read it bottom-up. A Tool is a Python function. A bunch of tools, plus an entry agent and maybe some specialists, plus a system prompt with policies, all decorated under one Profile, become one Graft's declarative config. That graft lives inside a Workspace. The host app pushes the config via agentgraft_sync, drops one widget tag, and the bubble appears.