|
| 1 | +import { |
| 2 | + agents, |
| 3 | + analytics, |
| 4 | + createAgent, |
| 5 | + createApp, |
| 6 | + files, |
| 7 | + fromPlugin, |
| 8 | + mcpServer, |
| 9 | + server, |
| 10 | + tool, |
| 11 | +} from "@databricks/appkit"; |
| 12 | +import { z } from "zod"; |
| 13 | + |
| 14 | +const port = Number(process.env.DATABRICKS_APP_PORT) || 8003; |
| 15 | + |
| 16 | +// Shared tool available to any agent that declares `tools: [get_weather]` in |
| 17 | +// its markdown frontmatter. |
| 18 | +const get_weather = tool({ |
| 19 | + name: "get_weather", |
| 20 | + description: "Get the current weather for a city", |
| 21 | + schema: z.object({ |
| 22 | + city: z.string().describe("City name"), |
| 23 | + }), |
| 24 | + execute: async ({ city }) => `The weather in ${city} is sunny, 22°C`, |
| 25 | +}); |
| 26 | + |
| 27 | +// Code-defined agent. Overrides config/agents/support.md if a file with that |
| 28 | +// name exists. Tools here are explicit; defaults are strict (no auto-inherit |
| 29 | +// for code-defined agents), so we pull analytics + files in via fromPlugin. |
| 30 | +const support = createAgent({ |
| 31 | + instructions: |
| 32 | + "You help customers with data analysis, file browsing, and general questions. " + |
| 33 | + "Use the available tools as needed and summarize results concisely.", |
| 34 | + tools: { |
| 35 | + ...fromPlugin(analytics), |
| 36 | + ...fromPlugin(files), |
| 37 | + get_weather, |
| 38 | + "mcp.vector-search": mcpServer( |
| 39 | + "vector-search", |
| 40 | + "https://e2-dogfood.staging.cloud.databricks.com/api/2.0/mcp/vector-search/main/default", |
| 41 | + ), |
| 42 | + "mcp.uc-greet": mcpServer( |
| 43 | + "uc-greet", |
| 44 | + "https://e2-dogfood.staging.cloud.databricks.com/api/2.0/mcp/functions/main/mario/greet", |
| 45 | + ), |
| 46 | + "mcp.mario-hello": mcpServer( |
| 47 | + "mario-mcp-hello", |
| 48 | + "https://mario-mcp-hello-6051921418418893.staging.aws.databricksapps.com/mcp", |
| 49 | + ), |
| 50 | + }, |
| 51 | +}); |
| 52 | + |
| 53 | +const appkit = await createApp({ |
| 54 | + plugins: [ |
| 55 | + server({ port }), |
| 56 | + analytics(), |
| 57 | + files(), |
| 58 | + agents({ |
| 59 | + // Ambient tool library referenced by markdown frontmatter `tools: [...]`. |
| 60 | + tools: { get_weather }, |
| 61 | + // Code-defined agents are merged with markdown agents; code wins on key |
| 62 | + // collision. Markdown agents still auto-inherit analytics+files tools |
| 63 | + // unless their frontmatter says otherwise. |
| 64 | + agents: { support }, |
| 65 | + }), |
| 66 | + ], |
| 67 | +}); |
| 68 | + |
| 69 | +const registry = appkit.agent as { |
| 70 | + list: () => string[]; |
| 71 | + getDefault: () => string | null; |
| 72 | +}; |
| 73 | +console.log( |
| 74 | + `Agent app running on port ${port}. Agents: ${registry.list().join(", ")}. Default: ${registry.getDefault() ?? "(none)"}.`, |
| 75 | +); |
0 commit comments