Artifact Storage

Persist large tool outputs to disk so agents can page through them on demand

When a tool returns more data than fits in context, Artifact Storage saves the overflow to disk and gives the agent tools to page through it — so nothing is silently lost.

python
from praisonaiagents import Agent
from praisonaiagents.config import ToolConfig

agent = Agent(
    name="Researcher",
    instructions="Research topics deeply.",
    tool_config=ToolConfig(enable_artifacts=True),
)
agent.start("Download and summarise the full release notes.")

The user asks for a large result; the agent stores the overflow as an artifact and pages through it with artifact tools instead of truncating silently.

Diagram

Artifact Overflow Flow

No

Yes

on demand

🔧 Tool Output

Size > limit?

📤 Inline result

💾 ArtifactStore

📝 Preview + ArtifactRef

🤖 Agent

🔍 artifact_head/tail/grep

Quick Start

  1. Enable with one line
    python
    from praisonaiagents import Agent
    from praisonaiagents.config import ToolConfig
    
    agent = Agent(
        name="Researcher",
        instructions="Research topics deeply",
        tools=[web_search],
        tool_config=ToolConfig(enable_artifacts=True)
    )
    
    agent.start("Summarise the latest LangChain release notes")
    # Large results are now saved to ~/.praisonai/artifacts/
    # instead of being silently truncated.

    The user asks for a summary; the agent reads artefacts from storage and replies.

  2. With configuration
    python
    from praisonaiagents import Agent
    from praisonaiagents.config import ToolConfig
    
    agent = Agent(
        name="Log Analyst",
        instructions="Analyse application logs",
        tools=[read_file],
        tool_config=ToolConfig(
            output_limit=32000,           # raise threshold to 32 KB
            enable_artifacts=True,
            artifact_retention_days=14,   # keep artifacts for 2 weeks
            redact_secrets=True,          # strip API keys / tokens before writing
        )
    )
    
    agent.start("Find errors in app.log from the last hour")
  3. With a custom artifact store
    python
    from praisonaiagents import Agent
    from praisonaiagents.config import ToolConfig
    from praisonaiagents.context import FileSystemArtifactStore
    
    store = FileSystemArtifactStore(base_dir="/data/my-artifacts")
    
    agent = Agent(
        name="Data Analyst",
        instructions="Analyse large datasets",
        tools=[query_database],
        tool_config=ToolConfig(
            enable_artifacts=True,
            artifact_store=store,
        )
    )

How It Works

Diagram
ArtifactStoreToolAgentUserArtifactStoreToolAgentUser“Summarise the release notes”Call web_search(…)200 KB of HTMLstore(content, metadata)ArtifactRef (path, summary, size)Preview + [ArtifactRef …] in contextartifact_grep(path, “breaking change”)Matching lines with contextSummary with key findings

When a tool returns output larger than output_limit, the agent:

  1. Writes the full content to ~/.praisonai/artifacts/{agent_id}/{run_id}/
  2. Replaces the oversize output with a short preview and an [ArtifactRef ...] line
  3. Gains six new tools (auto-registered) to page through the stored content

The agent picks these up autonomously — you do not call them manually.


Configuration Options

OptionTypeDefaultDescription
output_limitint16000Maximum bytes of tool output before spilling to the artifact store
output_max_linesintNoneMax lines kept from a tool’s output (None = no line cap). The line cap truncates; with enable_artifacts=True the full output is still stored as an artifact
output_directionstr"both"Which end(s) survive the line cap and the output_limit char cap: "head", "tail", or "both" (with a marker between)
enable_artifactsboolFalseMaster switch — enables artifact spillover. Off by default for backward compatibility
artifact_retention_daysint7Days to keep artifacts before garbage collection on agent destruction
artifact_storeAnyNoneCustom store instance — pass a FileSystemArtifactStore(...) or another ArtifactStoreProtocol implementation
redact_secretsboolTrueRedact common secret patterns (API keys, tokens, passwords) before writing to disk
timeoutintNoneTool execution timeout in seconds
retry_policyRetryPolicyNoneTool retry configuration
parallelboolFalseEnable parallel tool execution

Validation rules:

  • output_limit must be > 0
  • output_max_lines, if set, must be > 0
  • output_direction must be one of "head", "tail", or "both"
  • artifact_retention_days must be >= 0

Retrieval Tools the Agent Gains

These tools are auto-registered on first overflow — you do not add them manually.

ToolSignatureReturns
artifact_headartifact_head(artifact_path, lines=50)First N lines as a string
artifact_tailartifact_tail(artifact_path, lines=50)Last N lines as a string
artifact_grepartifact_grep(artifact_path, pattern, context_lines=2, max_matches=50)List of {line_number, line, context_before, context_after}
artifact_chunkartifact_chunk(artifact_path, start_line=1, end_line=None)Lines start_line..end_line (1-indexed, inclusive)
artifact_loadartifact_load(artifact_path)Full content (deserialised if JSON) — loads entire file into memory
artifact_listartifact_list(agent_id=None, run_id=None, tool_name=None)List of artifact metadata dicts

When a tool output is too large, the agent sees a truncated preview with a line like:

[Artifact from web_search: /home/user/.praisonai/artifacts/agent1/run1/abc123.artifact (204.8 KB) - First 200 chars of content...]

The agent then calls artifact_grep, artifact_chunk, or other tools autonomously to retrieve the parts it needs.


Storage Layout

Artifacts are stored under ~/.praisonai/artifacts/ by default:

~/.praisonai/artifacts/
└── {agent_id}/
    └── {run_id}/
        ├── {sha256[:12]}_{uuid8}.artifact       # raw content
        └── {sha256[:12]}_{uuid8}.meta.json      # metadata

The .meta.json file contains size, mime type, checksum (SHA256), tool name, and turn number.

Security: The store rejects any retrieval path outside base_dir and any extension other than .artifact. Keep this in mind when writing custom store implementations.

Cleanup: Artifacts older than artifact_retention_days are removed when the agent is finalized (garbage collected). Set artifact_retention_days=0 to disable retention-based cleanup.


Which Option Should I Use?

Diagram

Yes

No

No, preview is fine

Yes

Yes

No

Need to handle large tool output?

Output predictably small?

Leave defaults — enable_artifacts=False

Need full content recoverable?

Just raise output_limit

enable_artifacts=True

Contains secrets?

Keep redact_secrets=True default

Set redact_secrets=False for speed


Common Patterns

Long web scrapes

An agent scrapes a 200 KB page. The preview shows head and tail, and the agent uses artifact_grep to find “pricing” without re-scraping:

python
from praisonaiagents import Agent
from praisonaiagents.config import ToolConfig

agent = Agent(
    name="Web Researcher",
    instructions="Research pricing information from websites",
    tools=[web_scrape],
    tool_config=ToolConfig(
        enable_artifacts=True,
        output_limit=8000,
    )
)

agent.start("Find pricing tiers on stripe.com")
# Agent scrapes page → overflow stored → uses artifact_grep("pricing") autonomously

Log file analysis

read_file over a 5 MB log spills to disk. The agent uses artifact_chunk to inspect around an error timestamp:

python
from praisonaiagents import Agent
from praisonaiagents.config import ToolConfig

agent = Agent(
    name="Log Analyst",
    instructions="Find errors in application logs",
    tools=[read_file],
    tool_config=ToolConfig(
        enable_artifacts=True,
        output_limit=16000,
        artifact_retention_days=1,  # logs don't need long retention
    )
)

agent.start("Find what caused the 503 errors at 14:32 UTC in /var/log/app.log")
# Agent reads file → overflow stored → uses artifact_chunk(start_line=4500, end_line=4600)

Custom store backend

Power users can supply their own store instead of the filesystem default:

python
from praisonaiagents import Agent
from praisonaiagents.config import ToolConfig
from praisonaiagents.context import ArtifactStoreProtocol

class S3ArtifactStore:
    """Custom store that writes artifacts to S3."""
    def store(self, content, metadata): ...
    def load(self, ref): ...
    def head(self, ref, lines=50): ...
    def tail(self, ref, lines=50): ...
    def grep(self, ref, pattern, context_lines=2, max_matches=50): ...
    def chunk(self, ref, start_line=1, end_line=None): ...
    def list_artifacts(self, run_id=None, agent_id=None, tool_name=None): ...

agent = Agent(
    name="Cloud Analyst",
    instructions="Analyse cloud resources",
    tools=[fetch_cloud_data],
    tool_config=ToolConfig(
        enable_artifacts=True,
        artifact_store=S3ArtifactStore(bucket="my-artifacts"),
    )
)

Best Practices

Only enable for tools that produce large output

enable_artifacts=False by default means zero overhead. Enable it only for tools that regularly return large results — web scrapers, file readers, database queries, log fetchers.

Tune output_limit to your model's context budget

Set output_limit based on how much context your model can handle, not arbitrarily large. A value of 8,000–32,000 bytes works well for most models. Larger values mean less of the context window is available for the agent’s reasoning.

Set short retention in CI and sandboxes

Cleanup only runs on agent finalization (garbage collection). In CI environments or sandboxes, set artifact_retention_days=0 or artifact_retention_days=1 to avoid disk buildup if agents are not properly finalized.

Trust redact_secrets=True for any web or file tool

The default redact_secrets=True scans for API keys (api_key, secret, token), OpenAI keys (sk-...), and GitHub tokens (ghp_...) before writing to disk. Only disable it for known-safe content (e.g., structured scientific data with no credentials).


Related