Skip to main content

Prompt Blocks

Use client.prompt_blocks to manage registered prompt blocks. Static prompt blocks are stored editable body text. Dynamic prompt blocks are local AgentFlow runtime functions registered in the backend with @prompt_block; the SDK can list, preview, scope, enable/disable, order, and invalidate them, but it cannot edit dynamic code.

Create a static block

from agentflow import AsyncAgentFlow

async with AsyncAgentFlow.from_profile("prod") as client:
    block = await client.prompt_blocks.create(
        name="account_guidance",
        description="Guidance for account analysis.",
        message="system",
        type="static",
        mode="cached",
        scope="conversation",
        tags=["crm", "guidance"],
        body="When analyzing accounts, prioritize renewal risk and expansion signals.",
    )

List and retrieve

blocks = await client.prompt_blocks.list()
crm_context = await client.prompt_blocks.retrieve("crm_context")

Update metadata or static body

await client.prompt_blocks.update(
    "account_guidance",
    body="Prioritize renewal risk, expansion signals, and open executive asks.",
    order=45,
    enabled=True,
)

await client.prompt_blocks.update(
    "crm_context",
    ttl=1800,
    order=50,
    enabled=True,
)
Dynamic blocks reject body; update only metadata such as ttl, order, agents, tags, scope, mode, or enabled.

Preview and cache invalidation

preview = await client.prompt_blocks.preview(
    "account_guidance",
    body="Temporary preview body.",
)
print(preview.wrapped)

await client.prompt_blocks.invalidate_cache("crm_context")

Inline prompt blocks

Use inline prompt blocks when the client already has current-turn context, such as a selected record or current page. Inline blocks are not registered globally. AgentFlow wraps them, injects them as model-only system_context, and persists that hidden model input with the turn for replay.
from agentflow import InlinePromptBlock, RunOptions

result = await client.agents.run(
    agent_id=agent_id,
    message="What should I do next?",
    options=RunOptions(
        prompt_blocks=[
            InlinePromptBlock(
                name="selected_account",
                body="Acme Corp, ARR $120k, renewal in 31 days",
                tags=["selection", "context"],
            )
        ]
    ),
)
Normal chat UIs should show the user’s submitted message, not hidden inline block text.