Skip to content

Commit c4dd023

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

File tree

1 file changed

+246
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)