← Browse

@qredence/dspy-agent-framework-quick-ref

A

Quick reference card for DSPy + Agent Framework integration patterns: typed signatures, assertions, routing cache, and agent handoffs.

skillclaude

Install

agr install @qredence/dspy-agent-framework-quick-ref --target claude

Writes 1 file into .claude/skills/, pinned to git-76864ce6.

  • .claude/skills/dspy-agent-framework-quick-ref/SKILL.md

Document


name: dspy-agent-framework-quick-ref description: Quick reference card for DSPy + Agent Framework integration patterns: typed signatures, assertions, routing cache, and agent handoffs.

DSPy + Agent Framework Quick Reference

Typed Signatures

class TaskRouting(dspy.Signature):
    task: str = dspy.InputField(desc="Task to route")
    team: str = dspy.InputField(desc="Available agents")
    decision: RoutingDecisionOutput = dspy.OutputField()

class RoutingDecisionOutput(BaseModel):
    assigned_to: list[str] = Field(min_length=1)
    execution_mode: Literal["delegated", "sequential", "parallel"]
    subtasks: list[str] = Field(default_factory=list)
    tool_plan: list[str] = Field(default_factory=list)
    reasoning: str

DSPy Assertions

dspy.Assert(condition, "error message")  # Hard constraint
dspy.Suggest(condition, "guidance")       # Soft constraint

def validate_agent_exists(agents, available):
    Assert(len(agents) > 0, "Must assign at least one agent")
    for a in agents:
        Assert(a.lower() in [x.lower() for x in available],
               f"Agent {a} not in pool")

Routing Cache

class RoutingCache:
    def __init__(self, ttl_seconds=300, max_size=1024):
        self.ttl = ttl_seconds
        self.max_size = max_size

    def get(self, key): ...  # Returns None if expired/missing
    def set(self, key, value): ...  # Auto-evicts oldest
    def clear(self): ...

DSPy-Enhanced Agent

class DSPyEnhancedAgent(ChatAgent):
    def __init__(self, reasoning_strategy="chain_of_thought"):
        self.reasoning_strategy = reasoning_strategy
        if reasoning_strategy == "react":
            self.react_module = dspy.ReAct("q -> a", tools=self.tools)
        elif reasoning_strategy == "chain_of_thought":
            self.cot_module = dspy.ChainOfThought("q -> a")

Workflow with Checkpoints

from agent_framework._workflows import (
    WorkflowStartedEvent, WorkflowStatusEvent,
    WorkflowOutputEvent, ExecutorCompletedEvent,
    RequestInfoEvent, FileCheckpointStorage
)

class SupervisorWorkflow:
    def __init__(self, checkpoint_dir=".var/checkpoints"):
        self.checkpoint_storage = FileCheckpointStorage(checkpoint_dir)

    async def resume(self, checkpoint_id: str):
        state = self.checkpoint_storage.load(checkpoint_id)
        self.context.restore_from_state(state)

Agent Handoffs

class HandoffManager:
    def prepare_handoff(self, from_agent, to_agent, context):
        return {
            "task": context["original_task"],
            "findings": context.get("findings", []),
            "decisions": context.get("decisions", []),
            "from_agent_summary": self._summarize(from_agent)
        }

    def execute_sequential_with_handoffs(self, agents, tasks):
        context = {"original_task": tasks[0], "findings": [], "decisions": []}
        results = []
        for i, (agent, task) in enumerate(zip(agents, tasks)):
            handoff = self.prepare_handoff(
                agents[i-1] if i > 0 else None, agent, context
            )
            result = self._run_with_context(agent, task, handoff)
            context["findings"].extend(result.get("findings", []))
            results.append(result)
        return results

GEPA Optimization

agentic-fleet optimize  # Outputs: .var/cache/dspy/compiled_reasoner.json

Config:

dspy:
  use_typed_signatures: true
  enable_routing_cache: true
  routing_cache_ttl_seconds: 300
  optimization:
    use_gepa: true
    gepa_auto: light

Key Imports

# DSPy
import dspy
from dspy import TypedPredictor, ChainOfThought, ReAct, ProgramOfThought

# Agent Framework
from agent_framework._agents import ChatAgent
from agent_framework._workflows import Workflow, AgentThread
from agent_framework._types import AgentRunResponse, ChatMessage

# Pydantic
from pydantic import BaseModel, Field
from typing import Literal

Trustgrade A

  • passBody integrity

    Whether the stored document is plausibly the kind of file the artifact declares, rather than something fetched by mistake.

  • passType matchnot applicable to this artifact type

    Whether the artifact is really the kind of thing its metadata claims it is.

  • passFreshness

    How long since the source repository was last pushed to.

  • passPrompt injection

    Scans the artifact's own text for instructions aimed at your agent rather than at you.

  • passLicense

    Whether the source repository declares an SPDX license permissive enough to redistribute.

How the grade is calculated

Each check contributes 0 points when it passes, 1 when it warns, and 2 when it fails. The total maps to a letter:

  • Aevery check passed
  • Bone warning
  • Ctwo warnings
  • Dprompt injection or body integrity failed, or three warnings
  • Fone of those failed, and something else is wrong

These are automated hygiene checks, not a security audit, and not a dependency or vulnerability scan. A grade of A means nothing was flagged — not that the artifact is safe.

Versions

  • git-76864ce6c0ca2026-07-31