agent.tsx 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * Derived from vercel/ai-elements (skills/ai-elements/scripts/agent.tsx).
  3. * Copyright 2023 Vercel, Inc. Licensed under Apache-2.0.
  4. * Modified by ZCode: local integration, formatting and adaptations.
  5. * See THIRD-PARTY-NOTICES.md in the repository root for license and provenance.
  6. */
  7. "use client";
  8. import {
  9. Agent,
  10. AgentContent,
  11. AgentHeader,
  12. AgentInstructions,
  13. AgentOutput,
  14. AgentTool,
  15. AgentTools,
  16. } from "@/components/ai-elements/agent";
  17. import { z } from "zod";
  18. const webSearchTool = {
  19. description: "Search the web for information",
  20. inputSchema: z.object({
  21. query: z.string().describe("The search query"),
  22. }),
  23. };
  24. const readUrlTool = {
  25. description: "Read and parse a URL",
  26. inputSchema: z.object({
  27. url: z.string().url().describe("The URL to read"),
  28. }),
  29. };
  30. const summarizeTool = {
  31. description: "Summarize text into key points",
  32. inputSchema: z.object({
  33. maxPoints: z.number().optional().describe("Maximum number of key points"),
  34. text: z.string().describe("The text to summarize"),
  35. }),
  36. };
  37. const outputSchema = `z.object({
  38. sentiment: z.enum(['positive', 'negative', 'neutral']),
  39. score: z.number(),
  40. summary: z.string(),
  41. })`;
  42. const Example = () => (
  43. <Agent>
  44. <AgentHeader model="openai/gpt-5.2-pro" name="Research Assistant" />
  45. <AgentContent>
  46. <AgentInstructions>
  47. You are a helpful research assistant. Your job is to search the web for information and
  48. summarize findings for the user. Always cite your sources and provide accurate, up-to-date
  49. information.
  50. </AgentInstructions>
  51. <AgentTools type="multiple">
  52. <AgentTool tool={webSearchTool} value="web_search" />
  53. <AgentTool tool={readUrlTool} value="read_url" />
  54. <AgentTool tool={summarizeTool} value="summarize" />
  55. </AgentTools>
  56. <AgentOutput schema={outputSchema} />
  57. </AgentContent>
  58. </Agent>
  59. );
  60. export default Example;