Skip to content

Commit

Permalink
add filterParams tests
Browse files Browse the repository at this point in the history
  • Loading branch information
isamu committed May 10, 2024
1 parent 1b2372a commit 5532acf
Showing 1 changed file with 94 additions and 8 deletions.
102 changes: 94 additions & 8 deletions tests/agentFilters/test_filter_params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import test from "node:test";
import assert from "node:assert";

const httpAgentFilter: AgentFilterFunction = async (context, next) => {
console.log(context.filterParams);
return next(context);
};

Expand Down Expand Up @@ -36,7 +35,7 @@ test("test filterParams on agent filter", async () => {
agent: httpAgentFilter,
filterParams: {
agentServer: {
baseUrl: "http://localhost:8085/agents/",
baseUrl: "http://localhost:8085/agentFilters/",
stream: true,
},
},
Expand All @@ -47,11 +46,48 @@ test("test filterParams on agent filter", async () => {
const graph = new GraphAI({ ...graph_data }, { ...defaultTestAgents, ...callbackDictonary }, { agentFilters });

const result = await graph.run();
console.log(JSON.stringify(result));
assert.deepStrictEqual(result, { bypassAgent: [{ agentServer: { baseUrl: "http://localhost:8085/agents/", stream: true } }] });
// console.log(JSON.stringify(result));
assert.deepStrictEqual(result, { bypassAgent: [{ agentServer: { baseUrl: "http://localhost:8085/agentFilters/", stream: true } }] });
});

test("test filterParams on node", async () => {
const graph_data = {
version: 0.3,
nodes: {
echo: {
agent: "echoAgent",
params: {
filterParams: true,
},
filterParams: {
agentServer: {
baseUrl: "http://localhost:8081/nodeParameter/",
},
},
},
bypassAgent: {
agent: "bypassAgent",
inputs: [":echo"],
isResult: true,
},
},
};
const agentFilters = [
{
name: "httpAgentFilter",
agent: httpAgentFilter,
agentIds: ["echoAgent"],
},
];

const graph = new GraphAI({ ...graph_data }, { ...defaultTestAgents, ...callbackDictonary }, { agentFilters });

const result = await graph.run();
// console.log(JSON.stringify(result));
assert.deepStrictEqual(result, { bypassAgent: [{ agentServer: { baseUrl: "http://localhost:8081/nodeParameter/" } }] });
});

test("test filterParams on agent filter2", async () => {
test("test filterParams on agent filter and node. Then node.ts use filterParams on node", async () => {
const graph_data = {
version: 0.3,
nodes: {
Expand All @@ -62,7 +98,7 @@ test("test filterParams on agent filter2", async () => {
},
filterParams: {
agentServer: {
baseUrl: "http://localhost:8081/agents/",
baseUrl: "http://localhost:8081/nodeParameter/",
},
},
},
Expand All @@ -79,7 +115,7 @@ test("test filterParams on agent filter2", async () => {
agent: httpAgentFilter,
filterParams: {
agentServer: {
baseUrl: "http://localhost:8085/agents/",
baseUrl: "http://localhost:8085/agentFilters/",
stream: true,
},
},
Expand All @@ -91,5 +127,55 @@ test("test filterParams on agent filter2", async () => {

const result = await graph.run();
console.log(JSON.stringify(result));
assert.deepStrictEqual(result, { bypassAgent: [{ agentServer: { baseUrl: "http://localhost:8081/agents/", stream: true } }] });
assert.deepStrictEqual(result, { bypassAgent: [{ agentServer: { baseUrl: "http://localhost:8081/nodeParameter/" } }] });
});

test("test filterParams on each agent", async () => {
const graph_data = {
version: 0.3,
nodes: {
echo: {
agent: "echoAgent",
params: {
filterParams: true,
},
filterParams: {
agentServer: {
baseUrl: "http://localhost:8081/nodeParameter/",
},
},
},
echo2: {
agent: "echoAgent",
params: {
filterParams: true,
},
filterParams: {
agentServer: {
baseUrl: "http://localhost:8081/nodeParameter2/",
},
},
},
bypassAgent: {
agent: "bypassAgent",
inputs: [":echo", ":echo2"],
isResult: true,
},
},
};
const agentFilters = [
{
name: "httpAgentFilter",
agent: httpAgentFilter,
agentIds: ["echoAgent"],
},
];

const graph = new GraphAI({ ...graph_data }, { ...defaultTestAgents, ...callbackDictonary }, { agentFilters });

const result = await graph.run();
// console.log(JSON.stringify(result));
assert.deepStrictEqual(result, {
bypassAgent: [{ agentServer: { baseUrl: "http://localhost:8081/nodeParameter/" } }, { agentServer: { baseUrl: "http://localhost:8081/nodeParameter2/" } }],
});
});

0 comments on commit 5532acf

Please sign in to comment.