Last active
August 28, 2025 17:37
-
-
Save danield9tqh/f677dae95babedee672770eff4d110dc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { generateText, stepCountIs } from 'ai'; | |
| import { anthropic } from '@ai-sdk/anthropic'; | |
| import raindrop from 'raindrop-ai/otel'; | |
| import { createViewOnboardingConversationTool } from '../tools/viewOnboardingConversation'; | |
| import { createScheduleTweetTool } from '../tools/scheduleTweet'; | |
| import { Config } from '../../config'; | |
| interface AmbientAgentConfig { | |
| userId: string; | |
| } | |
| interface AmbientAgentResult { | |
| success: boolean; | |
| } | |
| export class VercelAmbientAgent { | |
| private userId: string; | |
| constructor(config: AmbientAgentConfig) { | |
| this.userId = config.userId; | |
| } | |
| async run(): Promise<AmbientAgentResult> { | |
| try { | |
| const systemPrompt = `You are an ambient marketing agent for a startup founder. Your job is to view their onboarding conversation and decide whether to schedule helpful tweets that align with their narrative pillars and business goals. | |
| IMPORTANT: You MUST follow this workflow: | |
| 1. First, ALWAYS call viewOnboardingConversation to see what the founder discussed | |
| 2. After receiving the conversation data, analyze it for key themes and narrative pillars | |
| 3. Based on the conversation content, schedule 3 relevant tweets that align with their pillars | |
| 4. Schedule a tweet for an appropriate time | |
| Be helpful but not overwhelming. Quality over quantity. Make sure the tweets reflect the founder's voice and business goals from the conversation.`; | |
| const userPrompt = `Please view the user's onboarding conversation and schedule 2-3 tweets based on their narrative pillars. You MUST call viewOnboardingConversation first, then call scheduleTweet multiple times.`; | |
| console.log('[VercelAmbientAgent] Starting agent for user', this.userId); | |
| // Create tools with userId bound in closure | |
| const viewConversationTool = createViewOnboardingConversationTool(this.userId); | |
| const scheduleTweetTool = createScheduleTweetTool(this.userId); | |
| await generateText({ | |
| model: anthropic('claude-3-5-sonnet-20241022'), | |
| system: systemPrompt, | |
| prompt: userPrompt, | |
| tools: { | |
| viewOnboardingConversation: viewConversationTool, | |
| scheduleTweet: scheduleTweetTool | |
| }, | |
| stopWhen: stepCountIs(10), | |
| temperature: 0.7, | |
| experimental_telemetry: { | |
| isEnabled: true, | |
| functionId: 'vercel-ambient-agent', | |
| metadata: { | |
| ...(Config.raindropApiKey ? raindrop.metadata({ | |
| userId: this.userId, | |
| eventName: 'ambient_agent_execution', | |
| convoId: `ambient-${Date.now()}`, | |
| }) : {}), | |
| environment: Config.environment, | |
| agentType: 'vercel-ambient', | |
| }, | |
| recordInputs: true, | |
| recordOutputs: true, | |
| }, | |
| onStepFinish: async (event) => { | |
| console.log(`[TELEMETRY DEBUG] Step Finished: ${event.content}`); | |
| if (event.toolCalls && event.toolCalls.length > 0) { | |
| for (const toolCall of event.toolCalls) { | |
| console.log(`[TELEMETRY DEBUG] Tool: ${toolCall.toolName}`); | |
| } | |
| } else { | |
| console.log(`[TELEMETRY DEBUG] Step Finished`); | |
| } | |
| } | |
| }); | |
| return { | |
| success: true, | |
| }; | |
| } catch (error) { | |
| console.error('[VercelAmbientAgent] Error:', error); | |
| return { success: false }; | |
| } | |
| } | |
| } | |
| // Factory function to create and run the agent | |
| export async function runVercelAmbientAgent(config: AmbientAgentConfig): Promise<AmbientAgentResult> { | |
| const agent = new VercelAmbientAgent(config); | |
| return agent.run(); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [Vercel Ambient Agent API] Triggering ambient agent for user Y7nSO5HL82zOx7FYXtrcr5wbeuKL8o2L | |
| [VercelAmbientAgent] Starting agent for user Y7nSO5HL82zOx7FYXtrcr5wbeuKL8o2L | |
| [ViewConversationTool] Returning conversation with 19 messages and 5 pillars | |
| [TELEMETRY DEBUG] Step Finished: I'll help you schedule some tweets based on the user's onboarding conversation. Let me check their conversation first. | |
| [TELEMETRY DEBUG] Tool: viewOnboardingConversation | |
| [TELEMETRY DEBUG] Step Finished: Based on the conversation, I see that the user is building an AI marketing assistant for founders to help manage their Twitter presence. The key narrative pillars are: | |
| 1. Founder Time Hacks | |
| 2. Twitter Growth Science | |
| 3. Automated Thought Leadership | |
| Let me schedule 3 relevant tweets that align with these pillars and reflect the founder's focus on helping early-stage founders save time while building their presence on Twitter. | |
| [TELEMETRY DEBUG] Tool: scheduleTweet | |
| [TELEMETRY DEBUG] Step Finished: | |
| [TELEMETRY DEBUG] Tool: scheduleTweet | |
| [TELEMETRY DEBUG] Step Finished: | |
| [TELEMETRY DEBUG] Tool: scheduleTweet | |
| [TELEMETRY DEBUG] Step Finished: I've scheduled 3 tweets that align with the founder's narrative pillars and business goals. The tweets are spaced throughout the day (9 AM, 2 PM, and 5 PM UTC) to maximize engagement. Each tweet: | |
| 1. Addresses the time-saving aspect (Founder Time Hacks) | |
| 2. Speaks to early-stage founders about getting started (Twitter Growth Science) | |
| 3. Highlights the vision of effortless thought leadership (Automated Thought Leadership) | |
| The tone is encouraging and practical, targeting early-stage founders who want to build their presence without spending too much time. The content reflects the founder's emphasis on making Twitter management more efficient while maintaining authenticity. | |
| [Vercel Ambient Agent API] Agent completed for user Y7nSO5HL82zOx7FYXtrcr5wbeuKL8o2L: { success: true } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment