Prompts¶
Auto-generated from source docstrings (mkdocstrings). The complete public contract is agentmaker.__all__ plus each subpackage __all__.
agentmaker.prompts: the framework's master prompt registry.
Collects every built-in prompt the framework feeds to the LLM into one enumerable, per-entry / whole-set overridable, validatable catalog, replacing constants that were scattered around, privately hard-coded, and unchangeable downstream. The design mirrors LlamaIndex's PromptMixin (get_prompts/update_prompts) plus first-class template objects:
PromptTemplate: one prompt = template text + declared placeholdersvariables+ protocol tokens that must be preserved verbatimprotected. Rendering only substitutes the declared{var}placeholders (non-placeholder braces such as{...}in JSON examples are left as-is); overriding validates that "placeholders + protocol tokens are still present".PromptRegistry: holds a set of PromptTemplates keyed bysubsystem.name(e.g.memory.extract/react.style/tool.error.not_found). Supportskeys()to list all,text(key)to read,render(key, **kw)to render,with_overrides({...})for a whole-set swap,override({...})for in-place change.DEFAULT_PROMPTS: the framework's default catalog (English). Each component reads prompts by key from the injected registry, so "what is listed" == "what is actually used" and they never drift.
Downstream usage (import after release, no source changes): agent.get_prompts() # list every prompt this agent actually uses agent.update_prompts({"memory.extract": "..."}) # override one entry (validates placeholders / protocol tokens) eng = DEFAULT_PROMPTS.with_overrides(my_english_pack) # swap the whole language, then feed it to components / agents
PromptError
¶
Bases: AgentmakerError
Prompt-related error: a missing placeholder at render time, or a lost required placeholder / protocol token on override. Inherits AgentmakerError so callers can catch it uniformly.
PromptRegistry
¶
A catalog of built-in prompts: list all / read / render / override by key.
with_overrides returns a new catalog with the overrides applied (the original is untouched); override mutates in place (all holders of the same instance see it); register adds a new key.
__init__(prompts)
¶
prompts: {key: PromptTemplate}.
__contains__(key)
¶
Support key in registry: whether the prompt is registered.
get(key)
¶
Return the PromptTemplate for a key; raises PromptError if it does not exist.
text(key)
¶
Return the current template text for a key.
render(key, **kwargs)
¶
Render (fill placeholders) by key.
keys()
¶
All keys (every registered prompt name).
as_dict()
¶
A {key: current template text} snapshot, for inspection / printing / export.
copy()
¶
Shallow copy (PromptTemplate is immutable, so copying the dict suffices): give each Agent its own copy so they never cross-mutate.
register(key, template, *, variables=(), protected=())
¶
Register a new prompt (only allowed if the key does not exist), letting third parties bring their custom strategy / tool prompts into the same enumerable / overridable / re-translatable system.
Use a namespace prefix (e.g. 'myapp.greeting') to avoid clashing with the framework's built-in keys. An existing key cannot be re-registered with this method (to prevent accidental overwrite): change an existing prompt via override / with_overrides. Typical usage: reg = DEFAULT_PROMPTS.copy(); reg.register('myapp.x', '...'); agent = Agent(..., prompts=reg), so that get_prompts() lists it fully and your own prompt pack can reach it via with_overrides.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
The prompt key (subsystem.name). |
required |
template
|
str
|
The template text. |
required |
variables
|
tuple
|
Placeholder names that must appear (validated on render, required to remain on override). |
()
|
protected
|
tuple
|
Protocol tokens that must be preserved verbatim (required to remain on override). |
()
|
with_overrides(updates)
¶
Return a new catalog with updates applied (the original is unchanged); each override passes with_text validation.
override(updates)
¶
Mutate this registry instance in place: every component holding the same instance sees the change. Used by Agent.update_prompts to propagate to already-built harness / sub-agents after construction. Calling it on the shared singleton DEFAULT_PROMPTS takes effect process-wide (for a global language switch), so when calling on DEFAULT_PROMPTS make sure it happens before creating any agent / tool (otherwise tool schemas are construction-time snapshots and you get a mix of languages).
PromptTemplate
¶
A single built-in prompt: template text + declared placeholders (variables) + protocol tokens that must be preserved verbatim (protected).
Rendering only substitutes the declared {var} placeholders; other braces (JSON examples, etc.) are left
as-is. Overriding enforces that placeholders and protocol tokens are still present, moving "missing placeholder /
broken protocol token" failures from run time forward to override time.
__init__(template, *, variables=(), protected=())
¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
template
|
str
|
The template text. |
required |
variables
|
tuple
|
Placeholder names that must appear (validated on render, required to remain on override). |
()
|
protected
|
tuple
|
Protocol tokens that must be preserved verbatim (required to remain on override, e.g. ReAct's "Action:", Chat's "[TOOL_CALL:"). |
()
|
render(**kwargs)
¶
Fill placeholders from keyword arguments and return the final text; raises PromptError if any declared variable is missing.
Only the declared {var} placeholders are substituted; other braces in the template (e.g. the JSON example
{"to":...}) are left as-is.
with_text(new_template)
¶
Return a new PromptTemplate with different text but the same variables / protected constraints; raises PromptError if the new text drops a placeholder or protocol token.