Skip to content

Commit e620fcf

Browse files
committed
rm context
1 parent 2f46da2 commit e620fcf

File tree

6 files changed

+24
-30
lines changed

6 files changed

+24
-30
lines changed

pnpm-lock.yaml

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scaffolds/src/agents/effective-agent-patterns/2.routing/routing.agent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export const routingAgent = pickaxe.agent({
4848
// STEP 1: Classification - Determine the type of request
4949
// This is the key step in routing - understanding what kind of input we have
5050
// so we can direct it to the most appropriate specialized handler
51-
const route = await routingToolbox.pickAndRun(ctx, {
51+
const route = await routingToolbox.pickAndRun({
5252
prompt: input.message,
5353
});
5454

scaffolds/src/agents/multi-agent.agent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export const rootAgent = pickaxe.agent({
4848
}),
4949
description: "A root agent that orchestrates the other agents",
5050
fn: async (input, ctx) => {
51-
const result = await multiAgentToolbox.pickAndRun(ctx, {
51+
const result = await multiAgentToolbox.pickAndRun({
5252
prompt: input.message,
5353
});
5454

scaffolds/src/agents/simple.agent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export const simpleAgent = pickaxe.agent({
2323
outputSchema: SimpleAgentOutput,
2424
description: "A simple agent to get the weather and time",
2525
fn: async (input, ctx) => {
26-
const result = await simpleToolbox.pickAndRun(ctx, {
26+
const result = await simpleToolbox.pickAndRun({
2727
prompt: input.message,
2828
});
2929

sdk/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
},
1717
"dependencies": {
1818
"@ai-sdk/openai": "^1.1.10",
19-
"@hatchet-dev/typescript-sdk": "^1.7.1",
19+
"@hatchet-dev/typescript-sdk": "^1.8.0",
2020
"ai": "^4.3.16",
2121
"axios": "^1.9.0",
2222
"json-schema-to-zod": "^2.6.1",

sdk/src/client/toolbox.ts

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
import { z } from "zod";
2-
import { generateText, jsonSchema, zodSchema } from "ai";
3-
import {
4-
Context,
5-
DurableContext,
6-
TaskWorkflowDeclaration,
7-
} from "@hatchet-dev/typescript-sdk";
2+
import { generateText, zodSchema } from "ai";
3+
import { TaskWorkflowDeclaration } from "@hatchet-dev/typescript-sdk";
84
import { Pickaxe, Registerable } from "./pickaxe";
9-
import jsonSchemaToZod from "json-schema-to-zod";
105

116
export interface ToolDeclaration<
127
InputSchema extends z.ZodType,
@@ -145,14 +140,12 @@ export class Toolbox<T extends ReadonlyArray<ToolDeclaration<any, any>>>
145140
* Uses the language model to choose up to `maxTools` tools from this toolbox that best satisfy
146141
* the provided prompt. Only the selection step is performed—no tool execution happens here.
147142
*
148-
* @param ctx - Durable context provided by the Hatchet runtime.
149143
* @param prompt - Natural-language description of what the caller wants to achieve.
150144
* @param [maxTools] - Optional upper bound on how many tools may be selected (defaults to 1).
151145
*
152146
* @returns An array containing the chosen tool names together with the generated input arguments.
153147
*/
154148
async pick(
155-
ctx: DurableContext<any> | Context<any>,
156149
{ prompt, maxTools }: PickInput
157150
) {
158151
const result = await pickToolFactory(this.client).run({
@@ -177,42 +170,43 @@ export class Toolbox<T extends ReadonlyArray<ToolDeclaration<any, any>>>
177170
* tools were selected.
178171
*
179172
* @typeParam R - Inferred map of tool names to transformer functions derived from the toolbox.
180-
* @param ctx - Durable context provided by the Hatchet runtime.
181173
* @param opts - Same input accepted by `pick`; the `maxTools` property determines the shape of the response.
182174
*/
183175
async pickAndRun<R extends TransformersFor<T>>(
184-
ctx: DurableContext<any> | Context<any>,
185176
opts: Omit<PickInput, "maxTools"> & { maxTools?: undefined }
186177
): Promise<ToolResultMap<T>>;
187178

188179
async pickAndRun<R extends TransformersFor<T>>(
189-
ctx: DurableContext<any> | Context<any>,
190180
opts: PickInput & { maxTools: 1 }
191181
): Promise<ToolResultMap<T>>;
192182

193183
// Overload: `maxTools` > 1 ➜ array of results
194184
async pickAndRun<R extends TransformersFor<T>>(
195-
ctx: DurableContext<any> | Context<any>,
196185
opts: PickInput & { maxTools: number }
197186
): Promise<ToolResultMap<T>[]>;
198187

199188
// Implementation
200189
async pickAndRun<R extends TransformersFor<T>>(
201-
ctx: DurableContext<any> | Context<any>,
202190
opts: PickInput
203191
): Promise<any> {
204192
// 1) pick tools
205-
const picked = await this.pick(ctx, opts);
193+
const picked = await this.pick(opts);
206194

207195
// 2) run them
208-
const results = await ctx.bulkRunChildren(
209-
picked.map(({ name, input }) => ({ workflow: name, input }))
196+
const results = await Promise.all(
197+
picked.map(async ({ name, input }) => {
198+
const tool = this.props.tools.find(t => t.name === name);
199+
if (!tool) {
200+
throw new Error(`Tool "${name}" not found in toolbox`);
201+
}
202+
return await tool.run(input);
203+
})
210204
);
211205

212206
// 3) zip back into the correctly typed union
213207
const zipped = picked.map(({ name, input }, i) => ({
214208
name,
215-
output: results[i][name], // FIXME: this is a hack to get the output of the tool
209+
output: results[i],
216210
args: input,
217211
})) as ToolResultMap<T>[];
218212

0 commit comments

Comments
 (0)