Skip to content

Commit

Permalink
Test tools can now pass commands to each other.
Browse files Browse the repository at this point in the history
  • Loading branch information
metaskills committed Jul 13, 2024
1 parent b3ee144 commit bb7bb8e
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 5 deletions.
23 changes: 23 additions & 0 deletions test/fixtures/echoTool.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,21 @@ class EchoTool extends Tool {
super({
name: helperName("EchoTool"),
instructions: "Echo the same text back to the user",
outputs: "tools",
tools: [
{
type: "function",
function: {
name: "marco",
description: "Use this tool if you get the /marco command.",
parameters: {
type: "object",
properties: { invoke: { type: "boolean" } },
required: ["invoke"],
},
},
},
],
parentsTools: [
{
type: "function",
Expand All @@ -22,6 +37,14 @@ class EchoTool extends Tool {
],
});
}

async ask(message, threadID, options = {}) {
const json = JSON.parse(message);
if (json.message === "marco") {
return "polo";
}
return await super.ask(message, threadID, options);
}
}

export { EchoTool };
2 changes: 1 addition & 1 deletion test/fixtures/routerAssistant.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class RouterAssistant extends Assistant {
name: helperName("Router"),
description: "Conversational Router",
instructions:
"Routes messages to the right tool. Send any message starting with the /echo command to the echo tool. If no tool can be found for the message, reply with one word 'unrouteable' as the error.",
"Routes messages to the right tool. Send any message starting with the /echo or /marco command to the echo tool. If no tool can be found for the message, reply with one word 'unrouteable' as the error.",
});
this.addAssistantTool(EchoTool);
}
Expand Down
23 changes: 19 additions & 4 deletions test/uat/router.test.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,31 @@
import { helperThread, helperThreadID } from "../helpers.js";
import { RouterAssistant } from "../fixtures.js";

test("using an assistant as router to the echo tool", async () => {
const assistant = await RouterAssistant.create();
let assistant;

beforeAll(async () => {
assistant = await RouterAssistant.create();
});

test("sends message to the echo tool", async () => {
const threadID = await helperThreadID();
const output = await assistant.ask("i need sales help", threadID);
const output = await assistant.ask("/hello", threadID);
expect(output).toMatch(/unrouteable/);
const output2 = await assistant.ask("/echo 123 hello", threadID);
expect(output2).toMatch(/123 hello/);
// Ensure each has own tread using metadata links.
});

test("each has own thread using metadata links", async () => {
const threadID = await helperThreadID();
await assistant.ask("/echo hello", threadID);
const thread = await helperThread(threadID);
expect(thread.metadata.echo).toMatch(/thread_/);
const thread2 = await helperThread(thread.metadata.echo);
expect(thread2.metadata.tool).toMatch(/Experts\.js \(EchoTool\)/);
});

test("commands can pass from tool to tool", async () => {
const threadID = await helperThreadID();
const output = await assistant.ask("/marco", threadID);
expect(output).toMatch(/polo/);
});

0 comments on commit bb7bb8e

Please sign in to comment.