@economic/agents 2.3.0 → 2.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +59 -0
- package/dist/providers.d.mts +2 -1
- package/dist/providers.mjs +4 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -27,6 +27,65 @@ npm install -D wrangler vite @cloudflare/vite-plugin @cloudflare/worker-bundler
|
|
|
27
27
|
|
|
28
28
|
`@economic/agents` provides the agent runtime. Worker apps install the Cloudflare/Agents host packages they import directly, including the Vite plugin stack used by native skills.
|
|
29
29
|
|
|
30
|
+
## Providers
|
|
31
|
+
|
|
32
|
+
`@economic/agents/providers` ships two pre-configured AI SDK providers that route through **Cloudflare AI Gateway** to Google Vertex AI and Google AI Studio. Both providers require `@ai-sdk/anthropic` and `@ai-sdk/google` to be installed.
|
|
33
|
+
|
|
34
|
+
### Anthropic via Vertex AI
|
|
35
|
+
|
|
36
|
+
Routes Claude models through Cloudflare AI Gateway → Google Vertex AI.
|
|
37
|
+
|
|
38
|
+
```typescript
|
|
39
|
+
import { createAnthropicVertexProvider } from "@economic/agents/providers";
|
|
40
|
+
|
|
41
|
+
const anthropic = createAnthropicVertexProvider({
|
|
42
|
+
cloudflareAccountId: env.CLOUDFLARE_ACCOUNT_ID,
|
|
43
|
+
cloudflareAiGatewayId: env.AI_GATEWAY_ID,
|
|
44
|
+
cloudflareApiToken: env.CLOUDFLARE_API_TOKEN,
|
|
45
|
+
googleCloudProjectId: env.GOOGLE_CLOUD_PROJECT_ID,
|
|
46
|
+
location: "europe-west1", // optional, defaults to "europe-west1"
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
getModel() {
|
|
50
|
+
return anthropic("claude-3-7-sonnet-20250219");
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Gemini via Vertex AI
|
|
55
|
+
|
|
56
|
+
Routes Gemini models through Cloudflare AI Gateway → Google Vertex AI.
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
import { createGeminiProvider } from "@economic/agents/providers";
|
|
60
|
+
|
|
61
|
+
const gemini = createGeminiProvider({
|
|
62
|
+
cloudflareAccountId: env.CLOUDFLARE_ACCOUNT_ID,
|
|
63
|
+
cloudflareAiGatewayId: env.AI_GATEWAY_ID,
|
|
64
|
+
cloudflareApiToken: env.CLOUDFLARE_API_TOKEN,
|
|
65
|
+
googleCloudProjectId: env.GOOGLE_CLOUD_PROJECT_ID,
|
|
66
|
+
location: "europe-west1", // optional, defaults to "europe-west1"
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
getModel() {
|
|
70
|
+
return gemini("gemini-2.0-flash");
|
|
71
|
+
}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Both together
|
|
75
|
+
|
|
76
|
+
`createAiGatewayVertexProviders` returns both providers from a single options object:
|
|
77
|
+
|
|
78
|
+
```typescript
|
|
79
|
+
import { createAiGatewayVertexProviders } from "@economic/agents/providers";
|
|
80
|
+
|
|
81
|
+
const { anthropic, gemini } = createAiGatewayVertexProviders({
|
|
82
|
+
cloudflareAccountId: env.CLOUDFLARE_ACCOUNT_ID,
|
|
83
|
+
cloudflareAiGatewayId: env.AI_GATEWAY_ID,
|
|
84
|
+
cloudflareApiToken: env.CLOUDFLARE_API_TOKEN,
|
|
85
|
+
googleCloudProjectId: env.GOOGLE_CLOUD_PROJECT_ID,
|
|
86
|
+
});
|
|
87
|
+
```
|
|
88
|
+
|
|
30
89
|
## Quick start: an agent
|
|
31
90
|
|
|
32
91
|
Subclass `Agent` and implement `getModel` and `getSystemPrompt`. Add tools with `getTools`, skills with `getSkills`. Expose a `@callable` method to run a turn — `saveMessages` injects a message, runs the turn, and persists the result:
|
package/dist/providers.d.mts
CHANGED
|
@@ -22,7 +22,8 @@ interface GeminiProviderOptions {
|
|
|
22
22
|
cloudflareAccountId: string;
|
|
23
23
|
cloudflareAiGatewayId: string;
|
|
24
24
|
cloudflareApiToken: string;
|
|
25
|
-
|
|
25
|
+
googleCloudProjectId: string;
|
|
26
|
+
location?: string;
|
|
26
27
|
}
|
|
27
28
|
declare function createGeminiProvider(options: GeminiProviderOptions): GoogleGenerativeAIProvider;
|
|
28
29
|
//#endregion
|
package/dist/providers.mjs
CHANGED
|
@@ -26,12 +26,12 @@ function createAnthropicVertexProvider(options) {
|
|
|
26
26
|
//#endregion
|
|
27
27
|
//#region src/providers/gemini.ts
|
|
28
28
|
function createGeminiProvider(options) {
|
|
29
|
-
const { cloudflareAccountId, cloudflareAiGatewayId, cloudflareApiToken,
|
|
29
|
+
const { cloudflareAccountId, cloudflareAiGatewayId, cloudflareApiToken, googleCloudProjectId, location = "europe-west1" } = options;
|
|
30
30
|
return createGoogleGenerativeAI({
|
|
31
|
-
apiKey:
|
|
32
|
-
baseURL: `https://gateway.ai.cloudflare.com/v1/${cloudflareAccountId}/${cloudflareAiGatewayId}/google-ai
|
|
31
|
+
apiKey: "unused",
|
|
32
|
+
baseURL: `https://gateway.ai.cloudflare.com/v1/${cloudflareAccountId}/${cloudflareAiGatewayId}/google-vertex-ai/v1/projects/${googleCloudProjectId}/locations/${location}/publishers/google/models`,
|
|
33
33
|
headers: { "cf-aig-authorization": `Bearer ${cloudflareApiToken}` },
|
|
34
|
-
name: "gateway.google.
|
|
34
|
+
name: "gateway.google.vertex-ai"
|
|
35
35
|
});
|
|
36
36
|
}
|
|
37
37
|
//#endregion
|