Skip to content

theinterneti/TTA.dev / .github/skills/ttadev-primitives

ttadev-primitives

Verified

Teaches TTA.dev primitive composition patterns so an AI agent can compose a working workflow in 1-2 turns. Use when the user wants to compose a workflow, use TTA.dev primitives, add a retry primitive, use workflow context, build a pipeline, or wire up any primitive (LambdaPrimitive, RetryPrimitive, TimeoutPrimitive, CachePrimitive, CircuitBreakerPrimitive, FallbackPrimitive, SequentialPrimitive, ParallelPrimitive). Covers the >> composition operator, WorkflowContext state passing, import paths, anti-patterns, and end-to-end workflow execution.

TTA.dev Primitive Composition

TTA.dev workflows are built by composing typed primitives — each a subclass of WorkflowPrimitive[Input, Output]. All primitives share a single execute interface and compose with >> (sequential) or | (parallel).

When to Use This Skill

  • Composing a new TTA.dev workflow from scratch
  • Wrapping an existing function in retry, timeout, or cache logic
  • Adding a circuit breaker to an external service call
  • Building a parallel fan-out or sequential pipeline
  • Passing state between steps with WorkflowContext

Prerequisites

uv sync            # installs ttadev and all extras

All primitives live in ttadev.primitives:

from ttadev.primitives import (
    WorkflowPrimitive, WorkflowContext, LambdaPrimitive,
    SequentialPrimitive, ParallelPrimitive,
    RetryPrimitive, TimeoutPrimitive, CachePrimitive,
    FallbackPrimitive,
)
from ttadev.primitives.recovery import CircuitBreakerPrimitive

Core Primitive Types

PrimitiveImport pathWhen to use
LambdaPrimitivettadev.primitivesWrap any function/async fn
SequentialPrimitivettadev.primitivesRun steps in order; output feeds next
ParallelPrimitivettadev.primitivesFan-out — same input, results list
RetryPrimitivettadev.primitivesTransient failures, exponential back-off
TimeoutPrimitivettadev.primitivesCap wall-clock time
CachePrimitivettadev.primitivesMemoize expensive calls
FallbackPrimitivettadev.primitivesTry primary, then secondary
CircuitBreakerPrimitivettadev.primitives.recoveryStop hammering a broken service

The >> Composition Operator

>> creates a SequentialPrimitive inline. The output of the left primitive becomes the input of the right primitive.

pipeline = step_a >> step_b >> step_c
result = await pipeline.execute(initial_input, ctx)

| creates a ParallelPrimitive — both sides receive the same input and run concurrently, returning list[Output].

fan_out = classifier | summariser
results = await fan_out.execute(text, ctx)   # [class_result, summary_result]

WorkflowContext — Passing State

WorkflowContext flows through every .execute() call. Use ctx.state to share values across steps without changing function signatures.

import asyncio
from ttadev.primitives import WorkflowContext, LambdaPrimitive

# Root context — starts a fresh workflow
ctx = WorkflowContext.root("my-pipeline")

# Write state in one step …
store = LambdaPrimitive(lambda data, c: (c.state.update({"key": data}), data)[1])

# … read it in another
read  = LambdaPrimitive(lambda _, c: c.state["key"].upper())

pipeline = store >> read
result = asyncio.run(pipeline.execute("hello", ctx))  # "HELLO"

Child contexts inherit state while keeping a new span ID:

child_ctx = WorkflowContext.child(ctx, step_name="validate-input")

Minimal Working Example

import asyncio
from ttadev.primitives import (
    LambdaPrimitive, RetryPrimitive, TimeoutPrimitive, WorkflowContext,
)

async def fetch(url: str, ctx: WorkflowContext) -> str:
    # … real HTTP call here
    return f"data from {url}"

fetcher = LambdaPrimitive(fetch)
resilient = TimeoutPrimitive(
    RetryPrimitive(fetcher, max_retries=3),
    timeout_seconds=10.0,
)

ctx = WorkflowContext.root("fetch-pipeline")
result = asyncio.run(resilient.execute("https://api.example.com/data", ctx))
print(result)

Recovery Primitives — Quick Reference

from ttadev.primitives import RetryPrimitive, TimeoutPrimitive, FallbackPrimitive
from ttadev.primitives.recovery import CircuitBreakerPrimitive, CircuitBreakerConfig

# Retry with exponential back-off
safe = RetryPrimitive(my_prim, max_retries=3, backoff_base=2.0)

# Hard wall-clock timeout
timed = TimeoutPrimitive(my_prim, timeout_seconds=5.0)

# Primary → fallback chain
resilient = FallbackPrimitive(primary_prim, fallback_prim)

# Circuit breaker — opens after 5 failures, retries after 60 s
cb = CircuitBreakerPrimitive(
    my_prim,
    config=CircuitBreakerConfig(failure_threshold=5, recovery_timeout=60.0),
)

Anti-Patterns

❌ Never do this✅ Use this instead
for attempt in range(3): try/exceptRetryPrimitive(prim, max_retries=3)
asyncio.wait_for(coro(), 10) manuallyTimeoutPrimitive(prim, timeout_seconds=10)
Global dict for workflow statectx.state["key"] = value
from primitives.X import ...from ttadev.primitives import ...
Hard-code retry counts in business logicWrap with RetryPrimitive

Running a Workflow End-to-End

import asyncio
from ttadev.primitives import (
    LambdaPrimitive, RetryPrimitive, CachePrimitive, WorkflowContext,
)

# 1. Define steps
validate = LambdaPrimitive(lambda x, _: x.strip() if x else ValueError("empty"))
enrich   = LambdaPrimitive(lambda x, _: {"text": x, "length": len(x)})

# 2. Compose
pipeline = (
    RetryPrimitive(validate, max_retries=2)
    >> enrich
)

# 3. Execute
ctx    = WorkflowContext.root("demo")
result = asyncio.run(pipeline.execute("  hello world  ", ctx))
print(result)  # {"text": "hello world", "length": 11}

Deep Reference

For parallel fan-out patterns, circuit breaker tuning, sequential data-passing, and FallbackPrimitive composition chains, see references/composition-patterns.md.

writing-skillsobra/superpowersUse when creating new skills, editing existing skills, or verifying skills work before deploymentStars: 318kUpdated Claude CodeCodexVerifiedInstall
xlsxanthropics/skillsUse this skill any time a spreadsheet file is the primary input or output. This means any task where the user wants to: open, read, edit, or fix an existing .xlsx, .xlsm, .xltx, .csv, or .tsv file (e.g., adding columns, computing formulas, formatting, charting, cleaning messy data); create a new spreadsheet from scratch or from other data sources; or convert between tabular file formats. Trigger especially when the user references a spreadsheet file by name or path — even casually (like "the xlsx in my downloads") — and wants something done to it or produced from it. Also trigger for cleaning or restructuring messy tabular data files (malformed rows, misplaced headers, junk data) into proper spreadsheets. The deliverable must be a spreadsheet file. Do NOT trigger when the primary deliverable is a Word document, HTML report, standalone Python script, database pipeline, or Google Sheets API integration, even if tabular data is involved.Stars: 196kUpdated Claude CodeCodexVerifiedInstall
shipping-and-launchaddyosmani/agent-skillsPrepares production launches. Use when preparing to deploy to production, or when asking what needs to be in place before shipping. Use when you need a pre-launch checklist, when setting up monitoring, when planning a staged rollout, or when you need a rollback strategy.Stars: 118kUpdated Claude CodeCodexVerifiedInstall
childhoodthedotmack/claude-memBabysit a shipped release after merge, publication, or deployment. Verify published packages, production behavior, installed plugins, and late CI or user reports until the observation window is clean; use babysit for PR readiness before release.Stars: 117kUpdated Claude CodeCodexVerifiedInstall