Skip to content

peteedoo/project-template / .agents/skills/imported/anomalyco--opencode/agents-sdk

agents-sdk

Verified

Build AI agents on Cloudflare Workers using the Agents SDK. Load when creating stateful agents, durable workflows, real-time WebSocket apps, scheduled tasks, MCP servers, or chat applications. Covers Agent class, state management, callable RPC, Workflows integration, and React hooks.

FileKindSize
SKILL.mdskill md6.2 KB
references/callable.mdmarkdown2.2 KB

references/callable.md

View on GitHub
# Callable Methods

Fetch `docs/callable-methods.md` from `https://github.com/cloudflare/agents/tree/main/docs` for complete documentation.

## Overview

`@callable()` exposes agent methods to clients via WebSocket RPC.

```typescript
import { Agent, callable } from "agents"

export class MyAgent extends Agent<Env, State> {
  @callable()
  async greet(name: string): Promise<string> {
    return `Hello, ${name}!`
  }

  @callable()
  async processData(data: unknown): Promise<Result> {
    // Long-running work
    return result
  }
}
```

## Client Usage

```typescript
// Basic call
const greeting = await agent.call("greet", ["World"])

// With timeout
const result = await agent.call("processData", [data], {
  timeout: 5000, // 5 second timeout
})
```

## Streaming Responses

```typescript
import { Agent, callable, StreamingResponse } from "agents"

export class MyAgent extends Agent<Env, State> {
  @callable({ streaming: true })
  async streamResults(stream: StreamingResponse, query: string) {
    for await (const item of fetchResults(query)) {
      stream.send(JSON.stringify(item))
    }
    stream.close()
  }

  @callable({ streaming: true })
  async streamWithError(stream: StreamingResponse) {
    try {
      // ... work
    } catch (error) {
      stream.error(error.message) // Signal error to client
      return
    }
    stream.close()
  }
}
```

Client with streaming:

```typescript
await agent.call("streamResults", ["search term"], {
  stream: {
    onChunk: (data) => console.log("Chunk:", data),
    onDone: () => console.log("Complete"),
    onError: (error) => console.error("Error:", error),
  },
})
```

## Introspection

```typescript
// Get list of callable methods on an agent
const methods = await agent.call("getCallableMethods", [])
// Returns: ["greet", "processData", "streamResults", ...]
```

## When to Use

| Scenario                             | Use                         |
| ------------------------------------ | --------------------------- |
| Browser/mobile calling agent         | `@callable()`               |
| External service calling agent       | `@callable()`               |
| Worker calling agent (same codebase) | DO RPC directly             |
| Agent calling another agent          | `getAgentByName()` + DO RPC |
reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis.Stars: 471kUpdated Claude CodeCodexVerifiedInstall
diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness.Stars: 322kUpdated Claude CodeCodexVerifiedInstall
dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependenciesStars: 322kUpdated Claude CodeCodexVerifiedInstall
executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is availableStars: 322kUpdated Claude CodeCodexVerifiedInstall