agentleFS
theinternetitheinterneti/TTA.dev/.github/skills/ttadev-primitives/SKILL.md

ttadev-primitives

Skill0 starsChanged 7 months agoMITView on GitHub

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.

The file

We split this skill into the rules it gives an agent

1 rule. About 0 are common, 0 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈0

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    All primitives live in ttadev.primitives:

    line 24

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.