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
This page shows you how to call your Agents from Workers, including approaches for how to address and route requests to Agents.
11
+
Learn how to call your Agents from Workers, including how to create Agents on-the-fly, address them, and route requests to specific instances of an Agent.
12
12
13
13
## Calling your Agent
14
14
15
-
TODO:
16
-
17
-
- created on the fly
18
-
- retrieved if exists
19
-
- naming
15
+
Agents are created on-the-fly and can serve multiple requests concurrently. Each Agent instance is isolated from other instances, can maintain its own state, and has a unique address.
20
16
21
17
You can create and run an instance of an Agent directly from a Worker in one of three ways:
22
18
@@ -71,17 +67,43 @@ export class MyAgent extends Agent<Env> {
71
67
72
68
### Naming your Agents
73
69
74
-
TODO:
70
+
When creating names for your Agents, think about what the Agent represents. A unique user? A team or company? A room or channel for collaboration?
71
+
72
+
A consistent approach to naming allows you to direct incoming requests directly to the right Agent, and deterministically route new requests back to that Agent, no matter where the client is in the world. For a given Agent definition (or 'namespace' in the code below), there can be millions (or tens of millions) of instances of that Agent, each handling their own requests, making calls to LLMs, and maintaining their own state.
73
+
74
+
For example, you might have an Agent for every user using your new AI-based code editor. In that case, you'd want to create Agents based on the user ID from your system, which would then allow that Agent to handle all requests for that user. It also ensures that [state within the Agent](/agents/api-reference/store-and-sync-state/), including chat history, language preferences, model configuration and other context can associated specifically with that user, making it easier to manage state.
0 commit comments