-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[bbrt] Support running breadboard components directly (#4118)
Regular breadboard components (e.g. GeminiKit, GoogleDriveKit) can now be executed directly by the main conversation. (Boards from the board server could already be executed).
- Loading branch information
Showing
6 changed files
with
200 additions
and
21 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
146 changes: 146 additions & 0 deletions
146
packages/bbrt/src/breadboard/breadboard-component-tool.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
/** | ||
* @license | ||
* Copyright 2025 Google LLC | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { | ||
createGraphStore, | ||
createLoader, | ||
type GraphDescriptor, | ||
type Kit, | ||
type NodeDescriberFunction, | ||
type NodeDescriptor, | ||
type NodeHandler, | ||
} from "@google-labs/breadboard"; | ||
import type { ArtifactHandle } from "../artifacts/artifact-interface.js"; | ||
import type { ArtifactStore } from "../artifacts/artifact-store.js"; | ||
import type { SecretsProvider } from "../secrets/secrets-provider.js"; | ||
import type { | ||
BBRTTool, | ||
BBRTToolAPI, | ||
BBRTToolMetadata, | ||
} from "../tools/tool-types.js"; | ||
import type { JsonSerializableObject } from "../util/json-serializable.js"; | ||
import type { Result } from "../util/result.js"; | ||
import { BreadboardToolInvocation } from "./breadboard-tool.js"; | ||
import { makeToolSafeName } from "./make-tool-safe-name.js"; | ||
import { standardizeBreadboardSchema } from "./standardize-breadboard-schema.js"; | ||
|
||
export class BreadboardComponentTool implements BBRTTool { | ||
readonly #kit: Kit; | ||
readonly #id: string; | ||
readonly #describe?: NodeDescriberFunction; | ||
readonly #secrets: SecretsProvider; | ||
readonly #artifacts: ArtifactStore; | ||
readonly #kits: Kit[]; | ||
|
||
constructor( | ||
kit: Kit, | ||
id: string, | ||
handler: NodeHandler, | ||
secrets: SecretsProvider, | ||
artifacts: ArtifactStore, | ||
kits: Kit[] | ||
) { | ||
this.#kit = kit; | ||
this.#id = id; | ||
this.#secrets = secrets; | ||
this.#artifacts = artifacts; | ||
this.#kits = kits; | ||
if ("describe" in handler) { | ||
this.#describe = handler.describe; | ||
} | ||
} | ||
|
||
get metadata(): BBRTToolMetadata { | ||
return { | ||
id: makeToolSafeName(`${this.#kit.url}_${this.#id}`), | ||
title: `${this.#kit.title}: ${this.#id}`, | ||
description: "TODO", | ||
icon: "/bbrt/images/tool.svg", | ||
}; | ||
} | ||
|
||
async api(): Promise<Result<BBRTToolAPI>> { | ||
const graphStore = createGraphStore({ | ||
kits: this.#kits, | ||
loader: createLoader(), | ||
sandbox: { | ||
runModule: () => { | ||
throw new Error("TODO: runModule not implemented"); | ||
}, | ||
}, | ||
}); | ||
|
||
if (this.#describe) { | ||
const { inputSchema, outputSchema } = await this.#describe( | ||
undefined, | ||
undefined, | ||
undefined, | ||
{ | ||
graphStore, | ||
outerGraph: { nodes: [], edges: [] }, | ||
wires: { incoming: {}, outgoing: {} }, | ||
} | ||
); | ||
return { | ||
ok: true, | ||
value: { | ||
inputSchema: standardizeBreadboardSchema(inputSchema), | ||
outputSchema: standardizeBreadboardSchema(outputSchema), | ||
}, | ||
}; | ||
} | ||
return { | ||
ok: true, | ||
value: { | ||
inputSchema: { type: "object", properties: {}, required: [] }, | ||
outputSchema: { type: "object", properties: {}, required: [] }, | ||
}, | ||
}; | ||
} | ||
|
||
execute(args: JsonSerializableObject) { | ||
return { result: this.#execute(args) }; | ||
} | ||
|
||
async #execute( | ||
args: JsonSerializableObject | ||
): Promise< | ||
Result<{ data: JsonSerializableObject; artifacts: ArtifactHandle[] }> | ||
> { | ||
const component: NodeDescriptor = { | ||
id: "component", | ||
type: this.#id, | ||
configuration: args, | ||
}; | ||
const bgl: GraphDescriptor = { | ||
nodes: [component], | ||
edges: [], | ||
}; | ||
const invocation = new BreadboardToolInvocation( | ||
args, | ||
async () => ({ ok: true, value: bgl }), | ||
this.#secrets, | ||
this.#artifacts, | ||
this.#kits | ||
); | ||
await invocation.start(); | ||
const state = invocation.state.get(); | ||
if (state.status === "success") { | ||
return { | ||
ok: true, | ||
value: { | ||
data: state.value.output as JsonSerializableObject, | ||
artifacts: state.value.artifacts, | ||
}, | ||
}; | ||
} else if (state.status === "error") { | ||
return { ok: false, error: state.error }; | ||
} else { | ||
state.status satisfies "running" | "unstarted"; | ||
return { ok: false, error: `Internal error: state was ${state.status}` }; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters