Context
Your agents often need background knowledge: runbooks, API docs, incident wikis, internal glossaries. Context lets you store that knowledge in context/*.md files and inject it into any prompt at compile time — instead of copy-pasting into every agent or making a live API call on every run.
context/
on_call_runbook.md # → {{ context.local('on_call_runbook') }}
data/
platform_overview.md # → {{ context.local('data/platform_overview') }}
Use it in any agent body or prompt template:
---
description: On-call specialist.
---
You handle data platform incidents.
{{ context.local('on_call_runbook', description='Team runbook') }}
At abt compile, abt reads context/on_call_runbook.md, resolves Jinja in it, and stores the result in manifest.json. At runtime, the content is injected into the prompt — no network call needed.
When to use context vs alternatives
| You want to... | Use |
|---|---|
| Inject a stable reference doc (runbook, glossary, API spec) | context.local() |
| Inject a page from Confluence | context.confluence() |
| Inject a file from a GitHub repo (e.g. a README) | context.github() |
| Inject a file from S3 | context.s3() |
| Substitute a value that changes between runs | {{ var('x') }} (not context) |
| Fetch live data per-run (Slack thread, Jira ticket) | sources/ (not context) |
Key distinction: context is resolved once at compile time and baked into the manifest. If the underlying document changes, re-run
abt compileto pick it up. If you need freshness on every run, usesources/instead.External context needs
--live.context.local()is always read at compile. The external providers (confluence,github,s3) are fetched only byabt compile --live(orflags: live_compile: true). A default compile makes no network call and records just the block'ssource:anddescription:. Under--livea failed fetch fails the compile.
Provider quick reference
context.local(name, …)
Reads context/<name>.md from your project. Supports Jinja inside the context file itself.
{{ context.local('on_call_runbook', description='Team runbook') }}
{{ context.local('data/platform_overview', max_chars=3000) }}
context.confluence(name, …)
Fetches one Confluence page at compile time (--live, see above). Requires abt-core[confluence] and credentials.
{{ context.confluence('incident_wiki', page_id='1000000000', space='XX',
description='Incident Management wiki') }}
Credentials live in profiles.yaml under credentials.atlassian (url/server, username/email, api_token) — see abt-atlassian-tools. Confluence Cloud only.
context.github(name, …)
Fetches one file from a GitHub repo at compile time (--live; e.g. a README baked into a prompt).
{{ context.github('runbook', repo='my-org/my-repo', path='docs/runbook.md') }}
Credentials (checked in order): inline token= kwarg, then profiles.yaml → credentials.github.token, then the GITHUB_TOKEN (or GH_TOKEN) env var — no optional dependency required. A token is required; the call raises if none of the three is set. The token is sent only to api.github.com, raw.githubusercontent.com and media.githubusercontent.com (large files are fetched from the download_url the API returns); a download_url on any other host is refused, and a redirect to another host is followed without the token.
context.s3(name, …)
Downloads one S3 object as UTF-8 text at compile time (--live).
{{ context.s3('model_card', bucket='my-bucket', key='docs/model_card.md') }}
Credentials come from boto3's standard resolution chain (env vars, ~/.aws/credentials, instance/task role) — there's no profiles.yaml entry for S3.
Consistency rule
The same context name must use identical kwargs everywhere it appears in the project. You cannot reference context.s3('x', max_chars=400) in one agent and context.s3('x') without max_chars in another — use a different name if you need different options.
Rendering mode
By default (auto), abt picks a strategy per agent: a path reference for delegating agents, inline text for plain agents and subagents. You can override this with context_mode:
# abt.yaml — project-wide default
config:
context_mode: lazy # auto | lazy | full
Or per-call in the template:
{{ context.local('api_reference', mode='lazy', description='API reference') }}
See Context methods → Rendering mode for full details.
Large context: delegating vs plain agents
For every agent, abt compile writes the context text to target/context/<provider>/ and stores two renderings of its prompt in manifest.json: one with the text inlined, one with a content_path reference to that file. target/compiled/<project>/agents/<name>.md always shows the content_path rendering, whatever the agent's kind, so don't read it as what a plain agent receives. The two kinds of agent (see the glossary) then get:
- Delegating agents (they declare
subagents:): thecontent_pathrendering. The agent reads the file with a file tool at runtime. Withmax_chars=, the firstmax_charscharacters are inlined as well. - Plain agents and subagents (no file tools): the inlined text, with no size warning. Add
max_chars=to cap it; anote: content truncatedmarker is appended when the cap applies.
The choice between the two renderings is made when the agent is built at run time, from whether the agent has file tools.
{{ context.local('large_runbook', max_chars=4000) }}
Selective compile
With abt compile -s my_agent (or abt run -s my_agent), only context reachable from that agent's delegation graph is fetched — faster iterations during development.
Docs catalog
abt docs generate includes a Context tab showing the manifest snapshot, provider, which agents use each context, and a content preview.
Extending: custom context providers
Register a project-local provider from providers/*.py with @context_provider("name"), giving your project {{ context.name(...) }}. The object needs a fetch(*, ref: ContextRef, project_root: Path) -> str method (and optionally source_string(ref) for nicer manifest labels):
# providers/context_providers.py
from pathlib import Path
from abt.context.refs import ContextRef
from abt.context.registry import context_provider
class LocalFileContextProvider:
def fetch(self, *, ref: ContextRef, project_root: Path) -> str:
path = str(ref.kwargs.get("path", "")).strip()
return (project_root / path).read_text(encoding="utf-8")
local_file_context_provider = context_provider("local_file")(LocalFileContextProvider())
Used from a prompt as {{ context.local_file('slot_name', path='...') }}. Third-party packages can also ship providers via the abt.context_providers entry-point group — the same mechanism context.confluence/context.github themselves use.
See also
- Context methods — full signature reference and env vars
- Jinja variables —
{{ var() }}and where templating is available - Sources — for per-run data (Slack, Jira, etc.)