Skip to content

Commit cc59fe8

Browse files
committed
docs
Signed-off-by: Hubert Zub <hubert.zub@databricks.com>
1 parent e20b96f commit cc59fe8

1 file changed

Lines changed: 238 additions & 0 deletions

File tree

Lines changed: 238 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,238 @@
1+
# @databricks/appkit-agent
2+
3+
Agent plugin for [Databricks AppKit](https://github.com/databricks/appkit). Adds a LangGraph-powered AI agent with streaming Responses API support and Databricks-hosted tool integration.
4+
5+
## Installation
6+
7+
```bash
8+
npm install @databricks/appkit-agent
9+
```
10+
11+
The LangChain peer dependencies are required when using the built-in ReAct agent (not needed if you provide a custom `agentInstance`):
12+
13+
```bash
14+
npm install @databricks/langchainjs @langchain/core @langchain/langgraph
15+
```
16+
17+
If you use hosted MCP tools (Genie, Vector Search, custom/external MCP servers):
18+
19+
```bash
20+
npm install @langchain/mcp-adapters
21+
```
22+
23+
## Quick Start
24+
25+
```typescript
26+
import { createApp, server } from "@databricks/appkit";
27+
import { agent } from "@databricks/appkit-agent";
28+
29+
const app = await createApp({
30+
plugins: [
31+
server(),
32+
agent({
33+
model: "databricks-claude-sonnet-4-5",
34+
systemPrompt: "You are a helpful assistant.",
35+
}),
36+
],
37+
});
38+
39+
app.server.start();
40+
```
41+
42+
The plugin registers `POST /api/agent` which accepts the [OpenAI Responses API](https://platform.openai.com/docs/api-reference/responses) request format with SSE streaming.
43+
44+
## Environment Variables
45+
46+
| Variable | Description |
47+
|---|---|
48+
| `DATABRICKS_MODEL` | Default model serving endpoint name. Overridden by `config.model`. |
49+
50+
## Configuration
51+
52+
```typescript
53+
agent({
54+
// Model serving endpoint (or set DATABRICKS_MODEL env var)
55+
model: "databricks-claude-sonnet-4-5",
56+
57+
// System prompt injected at the start of every conversation
58+
systemPrompt: "You are a helpful assistant.",
59+
60+
// Tools available to the agent (see Tools section below)
61+
tools: [myTool, genieTool],
62+
63+
// Or bring your own AgentInterface implementation (skips LangGraph setup)
64+
agentInstance: myCustomAgent,
65+
})
66+
```
67+
68+
## Tools
69+
70+
The agent supports two kinds of tools: **function tools** (local code) and **hosted tools** (Databricks-managed services).
71+
72+
### Function Tools
73+
74+
Define tools as plain objects following the OpenResponses FunctionTool schema:
75+
76+
```typescript
77+
import type { FunctionTool } from "@databricks/appkit-agent";
78+
79+
const weatherTool: FunctionTool = {
80+
type: "function",
81+
name: "get_weather",
82+
description: "Get the current weather for a location",
83+
parameters: {
84+
type: "object",
85+
properties: {
86+
location: {
87+
type: "string",
88+
description: "City name, e.g. 'San Francisco'",
89+
},
90+
},
91+
required: ["location"],
92+
},
93+
execute: async ({ location }) => {
94+
// Call your weather API here
95+
return `Weather in ${location}: sunny, 72°F`;
96+
},
97+
};
98+
99+
agent({ model: "databricks-claude-sonnet-4-5", tools: [weatherTool] });
100+
```
101+
102+
### Hosted Tools
103+
104+
Connect to Databricks-managed services without writing tool handlers:
105+
106+
```typescript
107+
// Genie Space — natural-language queries over your data
108+
const genie = {
109+
type: "genie-space" as const,
110+
genie_space: { id: "01efg..." },
111+
};
112+
113+
// Vector Search Index — semantic search over indexed documents
114+
const vectorSearch = {
115+
type: "vector_search_index" as const,
116+
vector_search_index: { name: "catalog.schema.my_index" },
117+
};
118+
119+
// Custom MCP Server — a Databricks App running an MCP server
120+
const customMcp = {
121+
type: "custom_mcp_server" as const,
122+
custom_mcp_server: { app_name: "my-app", app_url: "my-app-url" },
123+
};
124+
125+
// External MCP Server — a Unity Catalog connection to an external MCP endpoint
126+
const externalMcp = {
127+
type: "external_mcp_server" as const,
128+
external_mcp_server: { connection_name: "my-connection" },
129+
};
130+
131+
agent({
132+
model: "databricks-claude-sonnet-4-5",
133+
tools: [genie, vectorSearch, customMcp, externalMcp],
134+
});
135+
```
136+
137+
### Adding Tools After Creation
138+
139+
```typescript
140+
const app = await createApp({
141+
plugins: [
142+
server(),
143+
agent({ model: "databricks-claude-sonnet-4-5", tools: [weatherTool] }),
144+
],
145+
});
146+
147+
// Add more tools after the app is running
148+
await app.agent.addTools([timeTool]);
149+
```
150+
151+
## Programmatic API
152+
153+
After `createApp`, the plugin exposes methods on `app.agent`:
154+
155+
```typescript
156+
// Non-streaming invoke — returns the assistant's text reply
157+
const reply = await app.agent.invoke([
158+
{ role: "user", content: "What's the weather in SF?" },
159+
]);
160+
161+
// Streaming — yields Responses API SSE events
162+
for await (const event of app.agent.stream([
163+
{ role: "user", content: "Tell me a story" },
164+
])) {
165+
if (event.type === "response.output_text.delta") {
166+
process.stdout.write(event.delta);
167+
}
168+
}
169+
170+
// Add tools dynamically
171+
await app.agent.addTools([myNewTool]);
172+
```
173+
174+
## Databricks Apps Deployment
175+
176+
When deploying to Databricks Apps, alias the agent endpoint to `/invocations`:
177+
178+
```typescript
179+
app.server.extend((expressApp) => {
180+
expressApp.post("/invocations", (req, res) => {
181+
req.url = "/api/agent";
182+
expressApp(req, res);
183+
});
184+
});
185+
186+
app.server.start();
187+
```
188+
189+
## Custom Agent Implementation
190+
191+
To bring your own agent logic, implement the `AgentInterface` and pass it as `agentInstance`:
192+
193+
```typescript
194+
import type { AgentInterface, InvokeParams, ResponseOutputItem, ResponseStreamEvent } from "@databricks/appkit-agent";
195+
196+
class MyAgent implements AgentInterface {
197+
async invoke(params: InvokeParams): Promise<ResponseOutputItem[]> {
198+
// Your invoke logic — return Responses API output items
199+
}
200+
201+
async *stream(params: InvokeParams): AsyncGenerator<ResponseStreamEvent> {
202+
// Your streaming logic — yield Responses API SSE events
203+
}
204+
}
205+
206+
agent({ agentInstance: new MyAgent() });
207+
```
208+
209+
The `StandardAgent` class (exported from this package) provides a reference implementation that wraps a LangGraph `createReactAgent` and translates its stream events into Responses API format.
210+
211+
## API Reference
212+
213+
### Exports
214+
215+
| Export | Kind | Description |
216+
|---|---|---|
217+
| `agent` | Plugin factory | Main entry point — call with config, pass to `createApp` |
218+
| `StandardAgent` | Class | LangGraph-backed `AgentInterface` implementation |
219+
| `createInvokeHandler` | Function | Express handler factory for the `/api/agent` endpoint |
220+
| `isFunctionTool` | Function | Type guard for `FunctionTool` |
221+
| `isHostedTool` | Function | Type guard for `HostedTool` |
222+
223+
### Types
224+
225+
| Type | Description |
226+
|---|---|
227+
| `IAgentConfig` | Plugin configuration options |
228+
| `AgentInterface` | Contract for custom agent implementations |
229+
| `AgentTool` | Union of `FunctionTool \| HostedTool` |
230+
| `FunctionTool` | Local tool with JSON Schema parameters and `execute` handler |
231+
| `HostedTool` | Union of Genie, Vector Search, Custom MCP, External MCP tools |
232+
| `InvokeParams` | Input to `invoke()` / `stream()` |
233+
| `ResponseOutputItem` | Output item (message, function call, or function call output) |
234+
| `ResponseStreamEvent` | SSE event types for streaming responses |
235+
236+
## License
237+
238+
See [LICENSE](./LICENSE).

0 commit comments

Comments
 (0)