Skip to main content
Dynamic Context Discovery automatically queues large tool outputs to artifacts, preventing context flooding while enabling on-demand retrieval.

Quick Start

from praisonaiagents import Agent
from praisonai.context import setup_dynamic_context

ctx = setup_dynamic_context()

agent = Agent(
    instructions="You are a data analyst.",
    tools=ctx.get_tools(),
    hooks=[ctx.get_middleware()],
)

response = agent.chat("Fetch and analyze the large dataset")
What happens:
  • Large tool outputs (>32KB) are automatically saved as artifacts
  • Agent receives compact references instead of flooding context
  • Agent can use artifact_tail, artifact_grep to explore data on-demand

Configuration

ctx = setup_dynamic_context(
    inline_max_kb=16,       # Queue outputs > 16KB (default: 32)
    redact_secrets=True,    # Auto-redact API keys, passwords
    history_enabled=True,   # Persist conversation history
)

Available Tools

When you pass ctx.get_tools(), agents get:
ToolDescription
artifact_tailGet last N lines
artifact_headGet first N lines
artifact_grepSearch for pattern
artifact_chunkGet line range
artifact_listList artifacts

How It Works

Tool Output (large) → Middleware → ArtifactStore → ArtifactRef (inline)

                                            Agent uses artifact_tail/grep
  1. Middleware intercepts tool outputs
  2. Outputs > threshold are saved to ~/.praisonai/runs/
  3. Compact reference returned in context
  4. Agent uses artifact tools to explore data

Environment Variables

PRAISONAI_ARTIFACT_DIR=~/.praisonai/runs
PRAISONAI_ARTIFACT_INLINE_MAX_KB=32
PRAISONAI_ARTIFACT_REDACT=true

API Reference

setup_dynamic_context()

def setup_dynamic_context(
    base_dir: str = "~/.praisonai/runs",
    inline_max_kb: int = 32,
    redact_secrets: bool = True,
    history_enabled: bool = True,
    terminal_logging: bool = False,
) -> DynamicContextSetup

DynamicContextSetup

MethodReturns
get_tools()List of artifact tools for Agent(tools=...)
get_middleware()Queue middleware for Agent(hooks=...)

See Also