Skip to content

Commit

Permalink
Merge pull request #862 from isamu/globalConfig
Browse files Browse the repository at this point in the history
add global config
  • Loading branch information
snakajima authored Dec 29, 2024
2 parents c677da8 + 268672f commit 19a9328
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
16 changes: 15 additions & 1 deletion packages/graphai/src/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export class ComputedNode extends Node {
const agent = data.agent;
this.agentFunction = async ({ namedInputs, params }) => agent(namedInputs, params);
}
this.config = this.agentId ? (data.graph ? this.graph.config : ((this.graph.config ?? {})[this.agentId] ?? {})) : {};
this.config = this.getConfig(!!data.graph);

this.anyInput = data.anyInput ?? false;
this.inputs = data.inputs;
Expand Down Expand Up @@ -160,6 +160,20 @@ export class ComputedNode extends Node {
return this.agentId ?? "__custom__function"; // only for display purpose in the log.
}

private getConfig(hasGraphData: boolean) {
if (this.agentId) {
if (hasGraphData) {
return this.graph.config;
}
const config = this.graph.config ?? {};
return {
...(config["global"] ?? {}),
...(config[this.agentId] ?? {}),
};
}
return {};
}

private addPendingNode(nodeId: string) {
const source = parseNodeName(nodeId);
assert(!!source.nodeId, `Invalid data source ${nodeId}`);
Expand Down
4 changes: 2 additions & 2 deletions packages/graphai/tests/units/test_option_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ test("test graphai config option", async () => {
const testAgent: AgentFunction = async ({ config }) => {
return config;
};
const config = { testAgent: { message: "hello" } };
const config = { testAgent: { message: "hello" }, global: { userId: "test" } };
const graph = new GraphAI(graph_data, { testAgent: agentInfoWrapper(testAgent) }, { config });
const result = await graph.run();
assert.deepStrictEqual(result, { result: { message: "hello" } });
assert.deepStrictEqual(result, { result: { message: "hello", userId: "test" } });
});

const nested_graph_data = {
Expand Down

0 comments on commit 19a9328

Please sign in to comment.