Skip to content

Commit 4fbb8db

Browse files
committed
feat(cloudflare): Add cloudflare.json config and agent discovery
Bridges the gap with LangGraph and Mastra by adding declarative configuration: ## New Files ### cloudflare.json - Declarative agent configuration matching langgraph.json pattern - Lists all agents with metadata (path, export, description, model) - Server configuration (port, host) - Environment file location ### config-loader.ts - Utility functions for loading cloudflare.json - Agent discovery by name - Dynamic agent import support - Type-safe configuration access ## Benefits - ✅ Config file like LangGraph (langgraph.json) and Mastra (mastra.config.ts) - ✅ Agent metadata documented in one place - ✅ Enables future auto-discovery of agents - ✅ Server configuration centralized - ✅ Matches established integration patterns ## Current Agent Registry - agentic_chat (Llama 3.1 8B) - tool_based_generative_ui (Llama 3.3 70B) - agentic_generative_ui (Llama 3.1 8B) This completes the "lunchbox" by giving Cloudflare the same configuration capabilities as the other integrations.
1 parent c3b3bf9 commit 4fbb8db

File tree

2 files changed

+99
-0
lines changed

2 files changed

+99
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"dependencies": ["."],
3+
"agents": {
4+
"agentic_chat": {
5+
"path": "./src/agents/agentic_chat/agent.ts",
6+
"export": "getAgenticChatAgent",
7+
"description": "Basic chat with Llama 3.1 8B",
8+
"model": "@cf/meta/llama-3.1-8b-instruct"
9+
},
10+
"tool_based_generative_ui": {
11+
"path": "./src/agents/tool_based_generative_ui/agent.ts",
12+
"export": "getToolBasedGenerativeUiAgent",
13+
"description": "Tool-based UI with Llama 3.3 70B (haiku generation)",
14+
"model": "@cf/meta/llama-3.3-70b-instruct"
15+
},
16+
"agentic_generative_ui": {
17+
"path": "./src/agents/agentic_generative_ui/agent.ts",
18+
"export": "getAgenticGenerativeUiAgent",
19+
"description": "Progressive state updates with task steps",
20+
"model": "@cf/meta/llama-3.1-8b-instruct"
21+
}
22+
},
23+
"env": ".env",
24+
"server": {
25+
"port": 4114,
26+
"host": "0.0.0.0"
27+
}
28+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/**
2+
* Configuration loader for Cloudflare agents
3+
*
4+
* Reads cloudflare.json and provides utilities for agent discovery
5+
* and dynamic route registration.
6+
*/
7+
8+
import { readFileSync } from "fs";
9+
import { join } from "path";
10+
11+
export interface AgentConfig {
12+
path: string;
13+
export: string;
14+
description: string;
15+
model: string;
16+
}
17+
18+
export interface CloudflareConfig {
19+
dependencies: string[];
20+
agents: Record<string, AgentConfig>;
21+
env: string;
22+
server: {
23+
port: number;
24+
host: string;
25+
};
26+
}
27+
28+
/**
29+
* Load cloudflare.json configuration
30+
*/
31+
export function loadConfig(): CloudflareConfig {
32+
const configPath = join(process.cwd(), "cloudflare.json");
33+
const configContent = readFileSync(configPath, "utf-8");
34+
return JSON.parse(configContent);
35+
}
36+
37+
/**
38+
* Get list of all agent names
39+
*/
40+
export function getAgentNames(config: CloudflareConfig): string[] {
41+
return Object.keys(config.agents);
42+
}
43+
44+
/**
45+
* Get agent configuration by name
46+
*/
47+
export function getAgentConfig(config: CloudflareConfig, agentName: string): AgentConfig | undefined {
48+
return config.agents[agentName];
49+
}
50+
51+
/**
52+
* Dynamically import an agent getter function
53+
*/
54+
export async function loadAgentGetter(agentName: string, config: CloudflareConfig) {
55+
const agentConfig = getAgentConfig(config, agentName);
56+
if (!agentConfig) {
57+
throw new Error(`Agent "${agentName}" not found in cloudflare.json`);
58+
}
59+
60+
// Import the module
61+
const modulePath = agentConfig.path.replace("./src/", "../").replace(".ts", ".js");
62+
const module = await import(modulePath);
63+
64+
// Get the getter function
65+
const getterFunction = module[agentConfig.export];
66+
if (typeof getterFunction !== "function") {
67+
throw new Error(`Export "${agentConfig.export}" is not a function in ${agentConfig.path}`);
68+
}
69+
70+
return getterFunction;
71+
}

0 commit comments

Comments
 (0)