Dynamic Context Discovery

Artifact-based storage for large tool outputs

python
from praisonaiagents import Agent

agent = Agent(
    name="researcher",
    instructions="Use artifact tools when tool output is large.",
)
agent.start("Fetch the full API schema and summarise the auth section.")

Large tool outputs are queued to artifacts automatically — the agent sees compact references instead of flooding context, and explores data on demand with artifact tools.

The user asks for large data; middleware stores bulky tool output as artifacts and keeps compact references in context.

Diagram

Large Tool Output

Middleware

Artifact Store

Compact Ref in Context

Agent

artifact_grep / tail

Quick Start

  1. Enable dynamic context on an agent
    python
    from praisonaiagents import Agent
    from praisonai.context import setup_dynamic_context
    
    ctx = setup_dynamic_context()
    
    agent = Agent(
        name="Analyst",
        instructions="You are a data analyst.",
        tools=ctx.get_tools(),
        hooks=[ctx.get_middleware()],
    )
    
    agent.start("Fetch and analyse the large dataset")

    Outputs over 32 KB are saved as artifacts; the agent receives references and uses artifact_tail, artifact_grep, etc.

  2. Tune the inline threshold
    python
    ctx = setup_dynamic_context(
        inline_max_kb=16,
        redact_secrets=True,
        history_enabled=True,
    )

How It Works

Diagram
AgentArtifact storeMiddlewareToolAgentArtifact storeMiddlewareToollarge output (> inline_max_kb)save artifactcompact reference in contextartifact_grep / artifact_tailtargeted slice

Outputs above inline_max_kb are written to disk under base_dir. The agent sees a short reference and pulls only the lines it needs via artifact tools — context stays bounded even after heavy tool runs.


Available Tools

ToolDescription
artifact_tailLast N lines
artifact_headFirst N lines
artifact_grepSearch for pattern
artifact_chunkLine range
artifact_listList artifacts

Configuration

ParameterDefaultDescription
inline_max_kb32Queue outputs larger than this
redact_secretsTrueRedact API keys and passwords
history_enabledTruePersist conversation history
base_dir~/.praisonai/runsArtifact storage directory

Environment variables: PRAISONAI_ARTIFACT_DIR, PRAISONAI_ARTIFACT_INLINE_MAX_KB, PRAISONAI_ARTIFACT_REDACT.

Best Practices

Lower inline_max_kb for memory-heavy agents

16 KB keeps more headroom in context for long multi-tool sessions.

Keep redact_secrets enabled in production

Automatic redaction prevents credentials in tool output from reaching the LLM or disk logs.

Use artifact_grep before loading full files

Search artifacts first — avoid pulling entire multi-MB outputs into a single prompt.

Related