You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/docs/agents/api-reference/calling-agents.mdx
+66Lines changed: 66 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -59,6 +59,72 @@ export class MyAgent extends Agent<Env> {
59
59
```
60
60
</TypeScriptExample>
61
61
62
+
#### Calling methods directly
63
+
64
+
When using `getAgentByName`, you can pass both requests (including WebSocket) connections and call methods defined directly on the Agent itself using the native [JavaScript RPC](/workers/runtime-apis/rpc/) (JSRPC) API.
65
+
66
+
For example, once you have a handle (or "stub") to an unique instance of your Agent, you can call methods on it:
When using TypeScript, ensure you pass your Agent class as a TypeScript type parameter to the AgentNamespace type so that types are correctly inferred:
115
+
116
+
```ts
117
+
interfaceEnv {
118
+
// Passing your Agent class as a TypeScript type parameter allows you to call
0 commit comments