-
Notifications
You must be signed in to change notification settings - Fork 827
Feat/cloudflare integration - Fixes #475 #553
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Feat/cloudflare integration - Fixes #475 #553
Conversation
Ooooooh, this is exciting! |
This is awesome @Klammertime 🚀 We will start reviewing it shortly. |
@Klammertime Ok first of all, seriously great work on this! One request, can you add this to the dojo? Theres a few steps
Any new features would need to get added to To run the dojo,
both prep and run dojo everything can take a flag (mentioned above) to only run specific services. Some of the services will automatically die if they don't have the right env vars (e.g. pydantic-ai will die without an openai-api-key set, or langgraph will die without the .env file), so you'll need to either export/configure all of them (it should just be those 2 keys + the .env files for langgraph), or just run specific ones. the flag is For example if you just wanted to run mastra, pydantic-ai, and cloudflare, you could call
If you need help with any of that, or if it feels overwhelming at all (I know I just wall of texted pretty hard 😅 ) let me know and i can help get it all worked out. Also, if you feel up to copying over the E2E tests in the dojo/e2e folder for any features you implement, that would be awesome |
Thanks for the detailed instructions! I've added Cloudflare to the dojo. What's been added:
The server follows the same pattern as mastra/pydantic-ai - binds to 0.0.0.0:4114 and uses CLOUDFLARE_ACCOUNT_ID and CLOUDFLARE_API_TOKEN env vars. Currently starting with just Let me know if you'd like me to add any other features or if anything looks off. |
Wow, you already got that added, awesome! I hate to be the bearer of bad news, but I just pushed a very large reorganization of the repo. Basically, this needs to get moved from If you need a hand git-surgery-ing things around let me know. I'm out the next 2 days but I can grab it when I get back if you need a hand. Honestly the easiest solution might be to just move your branch to master and copy paste the new version in place. |
abc280a
to
0b40d4d
Compare
Adapts feat/cloudflare-integration to the new repository layout: - Move typescript-sdk/integrations/cloudflare → integrations/cloudflare/typescript - Move typescript-sdk/apps/dojo → apps/dojo - Update package.json repository directory path - Add workspace dependencies (@ag-ui/core, @ag-ui/client) All files relocated, dependencies updated, build passing ✅
Adds Cloudflare integration to dojo scripts and configuration: Scripts: - prep-dojo-everything.js: Add cloudflare prep target - run-dojo-everything.js: Add cloudflare service + CLOUDFLARE_URL env Configuration: - agents.ts: Add CloudflareHttpAgent for agentic_chat - env.ts: Add cloudflareUrl (default: localhost:4114) - menu.ts: Add Cloudflare to sidebar menu Only Cloudflare entries added - no changes to other integrations
Move example server files from examples/server/ to examples/ to match the langgraph typescript structure pattern. Dojo scripts already point to the correct location (examples/). Structure now matches other integrations: - integrations/cloudflare/typescript - library package - integrations/cloudflare/typescript/examples - demo server for dojo
…ctAgent Major refactoring to align Cloudflare integration with AG-UI protocol standards: ## Core Changes ### New CloudflareAgent Class - Extends AbstractAgent from @ag-ui/client (proper protocol compliance) - Returns Observable<BaseEvent> instead of AsyncGenerator - Uses proper event types from @ag-ui/core (TextMessageStartEvent, etc.) - Emits events with correct structure (messageId, threadId, runId) - Full streaming support with Cloudflare Workers AI ### Event System - RUN_STARTED/FINISHED events with threadId and runId - TEXT_MESSAGE_START/CONTENT/END with messageId - TOOL_CALL_START/ARGS/END with toolCallId - All events use proper TypeScript types from @ag-ui/core ### Agent Examples Structure - Reorganized to match LangGraph pattern: agents/{name}/agent.ts - Created AgenticChatAgent as first example (basic chat with Llama 3.1 8B) - Lazy initialization for environment variable handling - Express SSE handler with Observable subscription ### Dependencies - Added rxjs (7.8.1) and uuid (11.1.0) to integration - Added dotenv (16.4.5) to examples for env loading ### Workspace Configuration - Fixed pnpm-workspace.yaml to include all integration examples - Changed "integrations/mastra/typescript/examples" to "integrations/*/typescript/examples" - Ensures consistent workspace management across all integrations ### SDK Naming - Renamed CloudflareAgent interface to CloudflareAgentsSDKAgent - Prevents naming conflict with new CloudflareAgent class - Maintains backward compatibility for Agents SDK integration ## Testing - Server runs successfully on port 4114 - Tested with curl - proper SSE streaming confirmed - Events match AG-UI protocol specifications - Integration with Cloudflare Workers AI verified
…_ui agents Added two more agent examples to match AG-UI integration patterns: ## New Agents ### tool_based_generative_ui - Demonstrates frontend-provided tools (CopilotKit actions) - Uses Llama 3.3 70B for better tool calling support - System prompt focused on haiku generation - Frontend can render custom UI components for tool results - Emits proper TOOL_CALL_* events ### agentic_generative_ui - Demonstrates progressive state updates - Shows how UI can render structured data as it's generated - Emits STATE_SNAPSHOT events for real-time UI updates - Task breakdown example (steps with status) - Uses Llama 3.1 8B for step generation ## Server Updates - Updated Express server with both new routes - Enhanced health check to list all available agents - Improved console output with agent descriptions - Now serving 3 agents total: - agentic_chat - tool_based_generative_ui - agentic_generative_ui ## Testing - Server starts successfully with all 3 agents - Health endpoint returns agent list - All routes registered and accessible
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.
8f535ec
to
4fbb8db
Compare
Cloudflare Integration - Progress Update
Core Integration
Full Feature Set Remains
Configuration
Still To Do
Why the ArchitectureThe integration has two layers:
Everything builds clean and the three example agents work correctly with proper AG-UI event streaming. |
- Add @ag-ui/cloudflare dependency to dojo app - Register Cloudflare agents (agentic_chat, tool_based_generative_ui, agentic_generative_ui) - Update pnpm-workspace.yaml to include all integration examples consistently
…stent 3.3 - Changed tool_based_generative_ui agent from LLAMA_3_3_70B to LLAMA_3_1_70B - Removed LLAMA_3_3_70B from CLOUDFLARE_MODELS constant - All three agents now working and tested (agentic_chat, tool_based_generative_ui, agentic_generative_ui)
Updated the agentic_chat agent system prompt to explicitly instruct the model to only use tools when the user specifically requests them. Previously, the Llama 3.1 8B model was calling the change_background tool for simple greetings like "hi", which created a poor user experience. The enhanced system prompt now: - Only calls tools when explicitly requested by the user - Avoids tool calls for greetings and casual conversation - Responds conversationally by default
…behavior Added complete implementations for human-in-the-loop, shared state, and backend tool rendering demos to match feature parity with other integrations. Changes: - Add human_in_the_loop agent with interactive task planning - Add shared_state agent for persistent to-do list management - Add backend_tool_rendering agent for server-generated UI components - Improve agentic_chat system prompt to prevent inappropriate tool calls - Register all 6 agents in Dojo menu and content generation - Add .gitignore for integration-specific development files The Cloudflare integration now provides the same comprehensive demo experience as other framework integrations (LangGraph, Pydantic AI, etc.), showcasing all major AG-UI protocol features.
Comprehensive documentation update for the examples server: - Document all 6 agents (agentic_chat, tool_based_generative_ui, agentic_generative_ui, human_in_the_loop, shared_state, backend_tool_rendering) - Add model information and features for each agent - Include practical 'Try It' examples for testing - Add architecture overview and troubleshooting guide - Link to Dojo testing workflow - Fix markdown linting warnings
Active Development Update Current Work These are distinct Cloudflare products and deserve separate integrations following the pattern of other AG-UI integrations (langgraph, mastra, etc.). Working on this now. Will update when ready for review. |
Hey @Klammertime, no worries, it's completely fine to keep the PR open while you make improvements. Thanks for providing such detailed updates! |
Consolidates two separate Cloudflare integrations into a single unified package following the LangGraph pattern (one integration directory, multiple menu entries). ## Integration Structure **Single codebase** (`integrations/cloudflare/`): - Workers AI: Direct model inference via @cloudflare/ai API - Agents SDK: Framework with state management and Durable Objects **Two Dojo menu entries**: - "Cloudflare Workers AI" - Shows working demos (agentic_chat, tool_based_generative_ui) - "Cloudflare Agents SDK" - Shows SDK demos (human_in_the_loop, tool_based_generative_ui) Both point to same Express server on port 4114. ## Key Changes ### Package Capabilities - Full support for local HTTP development (Express/HTTP endpoints) - Full support for production Cloudflare Workers deployment - Exports all necessary utilities for both deployment modes - WebSocket support, Durable Objects integration, Workers adapters ### Model Updates - Updated to function-calling capable models where needed: - tool_based_generative_ui: LLAMA_3_3_70B_FP8 - backend_tool_rendering: LLAMA_3_3_70B_FP8 - Kept efficient models for simple chat: - agentic_chat: LLAMA_3_1_8B ### Agents SDK Integration - Added CloudflareAgentsSDKAdapter for translating Agents SDK → AG-UI protocol - Implemented human_in_the_loop_sdk with interrupt/approval workflow - Implemented tool_based_generative_ui_sdk with haiku generation - Proper tool call streaming, state management, and event emission ### Dojo Configuration - Removed non-working demos from menu (still available via npm package) - Only shows demos that work in local development context - Updated agents.ts and menu.ts for two-integration pattern ## Known Limitation: CopilotKit ThreadId Bug Several Workers AI agents are NOT shown in Dojo demo due to CopilotKit v1.10.6 bug: - backend_tool_rendering - agentic_generative_ui - shared_state - human_in_the_loop (Workers AI version) **Issue**: CopilotKit doesn't send requests from browser when threadId is present. **Impact**: Frontend tools are never sent to backend, causing agents to hallucinate responses instead of making proper tool calls. **Backend Status**: All agents work perfectly when tested via curl with tools provided. **Package Status**: All agents available and functional for npm package users who integrate with their own frontend (not CopilotKit). These agents remain in the codebase and are served by Express server for users of the @ag-ui/cloudflare npm package. ## Documentation - Comprehensive README explaining both deployment modes - Clear separation between local development and production Workers - Model selection guidance (function-calling vs general chat) - Usage examples for both Workers AI and Agents SDK ## Testing Backend verified working via curl: - Workers AI agents emit proper AG-UI events - Agents SDK adapter correctly translates events - Tool calling works with function-capable models (when tools provided)
No problem! Detailed updates help me keep track of what I've done :) The integration now follows the LangGraph pattern - one codebase with two menu entries in the Dojo. Both modes work great for local development with Express, and the package exports everything needed for production Workers deployment. I did run into an issue with CopilotKit v1.10.6 where it doesn't send requests when threadId is present, which blocks some of the demos from working in the Dojo viewer. The backend agents work perfectly when tested with curl though, so anyone using the npm package with their own frontend should be good to go. I updated models to use function-calling capable ones (Llama 3.3 70B) where needed, and added proper Agents SDK adapter with human-in-the-loop and tool-based generative UI examples. All the details are in the commit message and the new README. Happy to answer any questions! |
Add Cloudflare Integration
Fixes #475
Summary
This PR adds comprehensive Cloudflare support to AG-UI with three integration types:
Features
🤖 Workers AI Models
🏗️ Workers Runtime Support
🚀 Agents SDK Integration
Package Structure
Usage Examples
Basic Usage (Workers AI)
Deploy to Cloudflare Workers
With Cloudflare Agents SDK
Next.js Behind Cloudflare CDN
Available Models
@cf/meta/llama-3.1-8b-instruct
@cf/meta/llama-3.1-70b-instruct
@cf/meta/llama-3.3-70b-instruct
@cf/mistral/mistral-7b-instruct-v0.2
Testing
Implementation Notes
Following Mastra Integration Pattern
This integration follows the same structure as the approved
@ag-ui/mastra
integration:@ag-ui/cloudflare
(scoped)@ag-ui/core: workspace:*
examples/
directoryCloudflare-Specific Considerations
Header Normalization:
CF-Connecting-IP
overX-Forwarded-For
CF-Ray
for request tracingWorkers Runtime:
Agents SDK:
Agent.onChatMessage()
generatorsSTATE_SYNC
events when state changesDependencies
Peer Dependencies:
@ag-ui/core: workspace:*
@copilotkit/runtime: ^1.0.0
(optional)agents: ^0.1.0
(optional, for Agents SDK)Dev Dependencies:
@cloudflare/workers-types: ^4.20241112.0
tsup: ^8.3.5
Breaking Changes
None - this is a new integration.
Checklist
@ag-ui/cloudflare
)Additional Context
This integration enables developers to:
All three integration types work independently or together, providing flexibility for different use cases.