agent-respond
simple-ai/agent-respondFreeUtility
A function to respond to a message with an agent.
Live preview
live · rendered by the registry
Rendered by simple-ai on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://simple-ai.dev/r/agent-respond.jsonSource
1import type { Experimental_Agent as Agent } from "ai";2import { convertToModelMessages } from "ai";3import { AGENTS, type agentId } from "@/registry/ai/agents/agents-registry";4import type { AIUIMessage } from "@/registry/ai/messages";5import { idToReadableText } from "@/registry/lib/id-to-readable-text";67export function agentRoute(mentions: { id: string; name: string }[]): agentId {8 let mentionedAgentId = mentions?.[0]?.id;910 if (!mentionedAgentId) {11 mentionedAgentId = AGENTS[0];12 }1314 return mentionedAgentId as agentId;15}1617export async function agentExecute({18 agentId,19 agent,20 messages,21}: {22 agentId: string;23 // biome-ignore lint/suspicious/noExplicitAny: Agent type is not known24 agent: Agent<any, any, any>;25 messages: AIUIMessage[];26}) {27 const agentStream = agent.stream({28 messages: convertToModelMessages(messages),29 });3031 return agentStream.toUIMessageStreamResponse<AIUIMessage>({32 originalMessages: messages,33 sendReasoning: true,34 messageMetadata: ({ part }) => {35 if (part.type === "start") {36 return {37 timestamp: new Date().toISOString(),38 agent: {39 id: agentId,40 name: idToReadableText(agentId),41 },42 };43 }4445 if (part.type === "finish") {46 return {47 outputTokens: part.totalUsage.outputTokens,48 };49 }50 },51 });52}
What it pulls in
npm packages
Other registry items
Files it writes
More from simple-ai
All 77 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| agents-tools-registryagents-tools-registry | simple-ai | Utilities | Free | 1 dep · 2 files | |
| ai-utilsai-utils | simple-ai | Utilities | Free | 1 dep | |
| Exa Agentexa-agent | simple-ai | Utilities | Free | 1 dep | |
| exa-toolexa-tool | simple-ai | Utilities | Free | 3 deps | |
| Firecrawl Agentfirecrawl-agent | simple-ai | Utilities | Free | 1 dep | |
| firecrawl-toolfirecrawl-tool | simple-ai | Utilities | Free | 3 deps | |
| get-weatherget-weather | simple-ai | Utilities | Free | 2 deps | |
| id-to-readable-textid-to-readable-text | simple-ai | Utilities | Free | no deps |
