patterns

Reusable code patterns for building agents with the Haive framework, including basic, multi-engine, streaming, and error-recovery designs.

In plain words
What is it for?
Use them when creating Haive agents, defining their state, connecting processing steps, supporting streaming, or handling failures.
Why use it?
They provide starting structures for common agent workflows, so developers do not have to design the state and graph setup from scratch.

Agent

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add agents/pr1m8/haive/patterns
Clone the repo
git clone --depth 1 https://github.com/pr1m8/haive
Per session 0 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 1,400 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.01400
Opus 5 $0.00000 $0.00700
Sonnet 5 $0.00000 $0.00280
Haiku 4.5 $0.00000 $0.00140

Measured yesterday against content hash 89c6b1a78f69, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

patterns scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

project_docs/claude_sessions/claude_20250106_131930_example/agents/patterns.md · 234 lines

How it starts

The opening of the file, as written. The whole thing — 234 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Reusable Agent Patterns

Pattern: Basic Agent Structure

from haive.agents.base import Agent
from haive.core.schema import StateSchema
from haive.core.graph import BaseGraph
from pydantic import Field
from typing import List, Dict, Any, Optional

class CustomAgentState(StateSchema):
    """State schema for custom agent."""
    messages: List[str] = Field(default_factory=list)
    context: Dict[str, Any] = Field(default_factory=dict)

class CustomAgent(Agent[CustomAgentState]):
    """Custom agent implementation."""

    def __init__(
        self,
        name: str,
        engine: Any,
        **kwargs
    ) -> None:
        super().__init__(
            name=name,
            state_schema=CustomAgentState,
            **kwargs
        )
        self.engine = engine

    def setup_agent(self) -> None:
        """Initialize agent components."""
        self._sync_fields_from_engine()
        self._setup_schemas()
        self._build_initial_graph()

    def build_graph(self) -> BaseGraph:
        """Define agent workflow."""
        graph = BaseGraph()

        # Add your nodes here
        graph.add_node("start", self._process_input)
        graph.add_node("end", self._generate_output)

        # Define edges
        graph.add_edge("start", "end")
        graph.set_entry_point("start")

        return graph.compile()

Pattern: Multi-Engine Agent

class MultiEngineAgent(Agent[MultiEngineState]):
    """Agent using multiple engines for different tasks."""

    def __init__(
        self,
        name: str,
        main_engine: Any,
        tool_engine: Any,
        **kwargs
    ) -> None:
        super().__init__(name=name, **kwargs)
        self.main_engine = main_engine
        self.tool_engine = tool_engine

        # Register engines
        registry = EngineRegistry.get_instance()
        registry.register(main_engine)
        registry.register(tool_engine)

    def build_graph(self) -> BaseGraph:
        """Build graph with engine routing."""
        graph = BaseGraph()

        # Router node decides which engine
        graph.add_node("router", self._route_request)
        graph.add_node("main", self._use_main_engine)
        graph.add_node("tools", self._use_tool_engine)

        # Conditional routing
        graph.add_conditional_edge(
            "router",
            self._needs_tools,
            {
                True: "tools",
                False: "main"
            }
        )

        return graph.compile()

Read the full file on GitHub · 234 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. yesterday First seen · 234 lines · 0 tokens per session scan A 89c6b1a78f69

Subscribe to this mod's changes

patterns is an agent published in the GitHub repository pr1m8/haive (23 stars, last pushed 4mo ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 1,400 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.