Skip to content

Commit f4e2280

Browse files
committed
feat(appkit): modify tools api
Signed-off-by: Hubert Zub <hubert.zub@databricks.com>
1 parent 68c7bdd commit f4e2280

File tree

13 files changed

+507
-71
lines changed

13 files changed

+507
-71
lines changed
Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,44 @@
1-
import { tool } from "@langchain/core/tools";
2-
import { z } from "zod";
1+
import type { FunctionTool } from "@databricks/appkit";
32

4-
export const weatherTool = tool(
5-
async ({ location }) => {
3+
export const weatherTool: FunctionTool = {
4+
type: "function",
5+
name: "get_weather",
6+
description: "Get the current weather for a location",
7+
parameters: {
8+
type: "object",
9+
properties: {
10+
location: {
11+
type: "string",
12+
description: "City name, e.g. 'San Francisco'",
13+
},
14+
},
15+
required: ["location"],
16+
},
17+
execute: async ({ location }) => {
618
const conditions = ["sunny", "partly cloudy", "rainy", "windy"];
719
const condition = conditions[Math.floor(Math.random() * conditions.length)];
820
const temp = Math.floor(Math.random() * 30) + 50;
921
return `Weather in ${location}: ${condition}, ${temp}°F`;
1022
},
11-
{
12-
name: "get_weather",
13-
description: "Get the current weather for a location",
14-
schema: z.object({
15-
location: z.string().describe("City name, e.g. 'San Francisco'"),
16-
}),
17-
},
18-
);
23+
};
1924

20-
export const timeTool = tool(
21-
async ({ timezone }) => {
22-
const tz = timezone ?? "UTC";
23-
return `Current time in ${tz}: ${new Date().toLocaleString("en-US", { timeZone: tz })}`;
25+
export const timeTool: FunctionTool = {
26+
type: "function",
27+
name: "get_current_time",
28+
description: "Get the current date and time in a timezone",
29+
parameters: {
30+
type: "object",
31+
properties: {
32+
timezone: {
33+
type: "string",
34+
description: "IANA timezone, e.g. 'America/New_York'. Defaults to UTC",
35+
},
36+
},
2437
},
25-
{
26-
name: "get_current_time",
27-
description: "Get the current date and time in a timezone",
28-
schema: z.object({
29-
timezone: z
30-
.string()
31-
.optional()
32-
.describe("IANA timezone, e.g. 'America/New_York'. Defaults to UTC"),
33-
}),
38+
execute: async ({ timezone }) => {
39+
const tz = (timezone as string) ?? "UTC";
40+
return `Current time in ${tz}: ${new Date().toLocaleString("en-US", { timeZone: tz })}`;
3441
},
35-
);
42+
};
3643

3744
export const demoTools = { weatherTool, timeTool };
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Interface: FunctionTool
2+
3+
## Properties
4+
5+
### description?
6+
7+
```ts
8+
optional description: string | null;
9+
```
10+
11+
***
12+
13+
### execute()
14+
15+
```ts
16+
execute: (args: Record<string, unknown>) => string | Promise<string>;
17+
```
18+
19+
Handler invoked when the model calls this tool.
20+
21+
#### Parameters
22+
23+
| Parameter | Type |
24+
| ------ | ------ |
25+
| `args` | `Record`\<`string`, `unknown`\> |
26+
27+
#### Returns
28+
29+
`string` \| `Promise`\<`string`\>
30+
31+
***
32+
33+
### name
34+
35+
```ts
36+
name: string;
37+
```
38+
39+
***
40+
41+
### parameters?
42+
43+
```ts
44+
optional parameters: Record<string, unknown> | null;
45+
```
46+
47+
JSON Schema object describing the tool's parameters.
48+
49+
***
50+
51+
### strict?
52+
53+
```ts
54+
optional strict: boolean | null;
55+
```
56+
57+
***
58+
59+
### type
60+
61+
```ts
62+
type: "function";
63+
```

docs/docs/api/appkit/Interface.IAgentConfig.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# Interface: IAgentConfig
22

3-
Base configuration interface for AppKit plugins.
4-
5-
When you do **not** set `agentInstance`, the agent is built from `model`, `tools`, and `mcpServers`. You can then add more tools or MCP servers after app creation via `appkit.agent.addCapabilities()` (see [agent](Variable.agent.md) Plugin API).
3+
Base configuration interface for AppKit plugins
64

75
## Extends
86

@@ -27,7 +25,7 @@ When provided the plugin skips internal LangGraph setup and delegates
2725
directly to this instance. Use this to bring your own agent
2826
implementation or a different LangChain variant.
2927

30-
---
28+
***
3129

3230
### host?
3331

@@ -39,7 +37,7 @@ optional host: string;
3937

4038
[`BasePluginConfig`](Interface.BasePluginConfig.md).[`host`](Interface.BasePluginConfig.md#host)
4139

42-
---
40+
***
4341

4442
### maxTokens?
4543

@@ -49,17 +47,17 @@ optional maxTokens: number;
4947

5048
Max tokens to generate (default 2000). Ignored when `agentInstance` is provided.
5149

52-
---
50+
***
5351

5452
### mcpServers?
5553

5654
```ts
5755
optional mcpServers: DatabricksMCPServer[];
5856
```
5957

60-
MCP servers for Databricks tool integration. Ignored when `agentInstance` is provided. You can add more at runtime with `appkit.agent.addCapabilities({ mcpServers: [...] })`.
58+
MCP servers for Databricks tool integration. Ignored when `agentInstance` is provided.
6159

62-
---
60+
***
6361

6462
### model?
6563

@@ -71,7 +69,7 @@ Databricks model serving endpoint name (e.g. "databricks-claude-sonnet-4-5").
7169
Falls back to DATABRICKS_MODEL env var.
7270
Ignored when `agentInstance` is provided.
7371

74-
---
72+
***
7573

7674
### name?
7775

@@ -83,7 +81,7 @@ optional name: string;
8381

8482
[`BasePluginConfig`](Interface.BasePluginConfig.md).[`name`](Interface.BasePluginConfig.md#name)
8583

86-
---
84+
***
8785

8886
### systemPrompt?
8987

@@ -93,7 +91,7 @@ optional systemPrompt: string;
9391

9492
System prompt injected at the start of every conversation
9593

96-
---
94+
***
9795

9896
### telemetry?
9997

@@ -105,7 +103,7 @@ optional telemetry: TelemetryOptions;
105103

106104
[`BasePluginConfig`](Interface.BasePluginConfig.md).[`telemetry`](Interface.BasePluginConfig.md#telemetry)
107105

108-
---
106+
***
109107

110108
### temperature?
111109

@@ -115,17 +113,19 @@ optional temperature: number;
115113

116114
Sampling temperature (0.0-1.0, default 0.1). Ignored when `agentInstance` is provided.
117115

118-
---
116+
***
119117

120118
### tools?
121119

122120
```ts
123-
optional tools: StructuredTool<ToolInputSchemaBase, any, any, any>[];
121+
optional tools: AgentTool[];
124122
```
125123

126-
Additional LangChain tools to register alongside MCP tools. Ignored when `agentInstance` is provided. You can add more at runtime with `appkit.agent.addCapabilities({ tools: [...] })`.
124+
Tools to register with the agent. Accepts OpenResponses-aligned FunctionTool
125+
objects or LangChain StructuredToolInterface instances.
126+
Ignored when `agentInstance` is provided.
127127

128-
---
128+
***
129129

130130
### useResponsesApi?
131131

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Type Alias: AgentTool
2+
3+
```ts
4+
type AgentTool = FunctionTool | StructuredToolInterface;
5+
```
6+
7+
A tool that can be registered with the agent plugin.
8+
9+
- `FunctionTool` (preferred): OpenResponses-aligned plain object with JSON Schema parameters.
10+
- `StructuredToolInterface`: LangChain tool for advanced use cases.
Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,5 @@
11
# Variable: agent
22

33
```ts
4-
const agent: ToPlugin<typeof AgentPlugin, IAgentConfig, "agent">;
4+
const agent: ToPlugin<typeof AgentPlugin, IAgentConfig, string>;
55
```
6-
7-
Plugin factory for the AppKit agent (LangChain/LangGraph). Use in `createApp({ plugins: [agent({ ... })] })`. Configuration: [`IAgentConfig`](Interface.IAgentConfig.md).
8-
9-
## Plugin API (runtime)
10-
11-
After `const appkit = await createApp({ plugins: [..., agent(config)] })`, `appkit.agent` exposes:
12-
13-
| Method | Description |
14-
| ------ | ------ |
15-
| `invoke(messages)` | Run the agent (non-streaming). Returns the assistant reply text. |
16-
| `stream(messages)` | Run the agent with streaming. Yields [`ResponseStreamEvent`](TypeAlias.ResponseStreamEvent.md)s. |
17-
| `addCapabilities({ tools?, mcpServers? })` | Batch-add tools and/or MCP servers with a **single** agent rebuild. **Only when not using `agentInstance`.** |
18-
| `addTools(tools)` | Add LangChain tools after app creation. Rebuilds the agent. Convenience wrapper around `addCapabilities`. **Only when not using `agentInstance`.** |
19-
| `addMcpServers(servers)` | Add MCP servers after app creation. Rebuilds the agent and MCP client. Convenience wrapper around `addCapabilities`. **Only when not using `agentInstance`.** |
20-
21-
When the plugin is configured with `model` and optional `tools` / `mcpServers` (i.e. without `agentInstance`), prefer `addCapabilities` to register both tools and MCP servers in one call instead of sequential `addTools` + `addMcpServers` (which would rebuild the agent twice).

docs/docs/api/appkit/index.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ plugin architecture, and React integration.
3434
| [BasePluginConfig](Interface.BasePluginConfig.md) | Base configuration interface for AppKit plugins |
3535
| [CacheConfig](Interface.CacheConfig.md) | Configuration for caching |
3636
| [DatabaseCredential](Interface.DatabaseCredential.md) | Database credentials with OAuth token for Postgres connection |
37+
| [FunctionTool](Interface.FunctionTool.md) | - |
3738
| [GenerateDatabaseCredentialRequest](Interface.GenerateDatabaseCredentialRequest.md) | Request parameters for generating database OAuth credentials |
3839
| [IAgentConfig](Interface.IAgentConfig.md) | Base configuration interface for AppKit plugins |
3940
| [InvokeParams](Interface.InvokeParams.md) | Agent interface types for the AppKit Agent Plugin. |
@@ -54,6 +55,7 @@ plugin architecture, and React integration.
5455

5556
| Type Alias | Description |
5657
| ------ | ------ |
58+
| [AgentTool](TypeAlias.AgentTool.md) | A tool that can be registered with the agent plugin. |
5759
| [ConfigSchema](TypeAlias.ConfigSchema.md) | Configuration schema definition for plugin config. Re-exported from the standard JSON Schema Draft 7 types. |
5860
| [IAppRouter](TypeAlias.IAppRouter.md) | Express router type for plugin route registration |
5961
| [PluginData](TypeAlias.PluginData.md) | - |
@@ -65,7 +67,7 @@ plugin architecture, and React integration.
6567

6668
| Variable | Description |
6769
| ------ | ------ |
68-
| [agent](Variable.agent.md) | Agent plugin factory; runtime API includes invoke, stream, addCapabilities, addTools, addMcpServers. |
70+
| [agent](Variable.agent.md) | - |
6971
| [sql](Variable.sql.md) | SQL helper namespace |
7072

7173
## Functions

docs/docs/api/appkit/typedoc-sidebar.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ const typedocSidebar: SidebarsConfig = {
102102
id: "api/appkit/Interface.DatabaseCredential",
103103
label: "DatabaseCredential"
104104
},
105+
{
106+
type: "doc",
107+
id: "api/appkit/Interface.FunctionTool",
108+
label: "FunctionTool"
109+
},
105110
{
106111
type: "doc",
107112
id: "api/appkit/Interface.GenerateDatabaseCredentialRequest",
@@ -183,6 +188,11 @@ const typedocSidebar: SidebarsConfig = {
183188
type: "category",
184189
label: "Type Aliases",
185190
items: [
191+
{
192+
type: "doc",
193+
id: "api/appkit/TypeAlias.AgentTool",
194+
label: "AgentTool"
195+
},
186196
{
187197
type: "doc",
188198
id: "api/appkit/TypeAlias.ConfigSchema",

packages/appkit/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ export { Plugin, type ToPlugin, toPlugin } from "./plugin";
5151
export { agent, analytics, files, genie, lakebase, server } from "./plugins";
5252
export type {
5353
AgentInterface,
54+
AgentTool,
55+
FunctionTool,
5456
IAgentConfig,
5557
InvokeParams,
5658
ResponseStreamEvent,

0 commit comments

Comments
 (0)