---
title: Custom loops
description: Manual spans on the OTEL tracer.
---

# Custom loops

If you are not on OpenAI / Anthropic / LangChain, keep `init()` and `@check`. Spans still go out over OTLP. Record tools with OpenInference attributes so receipts can see them.

```python
from opentelemetry import trace
import agenko

agenko.init()
tracer = trace.get_tracer("my-agent")

@agenko.check(claims="billing.refund")
def refund(order_id: str):
    with tracer.start_as_current_span("refund") as span:
        span.set_attribute("openinference.span.kind", "TOOL")
        span.set_attribute("tool.name", "billing.refund")
        return provider.refund(order_id)
```

```typescript
import { trace } from "@opentelemetry/api";
import agenko from "@agenko/sdk";

agenko.init();
const tracer = trace.getTracer("my-agent");

const refund = agenko.check({ claims: "billing.refund" }, async (orderId: string) => {
  return tracer.startActiveSpan("refund", async (span) => {
    span.setAttribute("openinference.span.kind", "TOOL");
    span.setAttribute("tool.name", "billing.refund");
    try {
      return await provider.refund(orderId);
    } finally {
      span.end();
    }
  });
});
```

## Attribute contract

See `agenko/spec/telemetry/semantic-conventions.yaml` in the repo. Prefer OpenInference names. `agenko.*` is for receipt/gate fields the upstream spec does not have.

Do not invent a parallel tracer. Attach to the provider `init()` installed.

## Agent instructions

This page: https://docs.agenko.app/custom-loops.md

Fetch `/llms.txt` for the full index. Search: `GET /api/search-docs?query=...`
