Skip to content

Commit 5871cdc

Browse files
fix(langchain): support for BaseCallbackConfig in agent config (#9291)
1 parent dc7f3f5 commit 5871cdc

File tree

2 files changed

+41
-7
lines changed

2 files changed

+41
-7
lines changed

libs/langchain/src/agents/runtime.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import type {
66
PregelOptions,
77
} from "@langchain/langgraph";
88
import type { BaseMessage } from "@langchain/core/messages";
9+
import type { BaseCallbackConfig } from "@langchain/core/callbacks/manager";
910

1011
import type { ResponseFormatUndefined } from "./responses.js";
1112

@@ -152,17 +153,24 @@ export type InvokeConfiguration<ContextSchema extends Record<string, any>> =
152153
* If the context schema is a default object, `context` can be optional
153154
*/
154155
ContextSchema extends InteropZodDefault<any>
155-
? Partial<Pick<PregelOptions<any, any, any>, CreateAgentPregelOptions>> & {
156-
context?: Partial<ContextSchema>;
157-
}
156+
? BaseCallbackConfig &
157+
Partial<
158+
Pick<PregelOptions<any, any, any>, CreateAgentPregelOptions>
159+
> & {
160+
context?: Partial<ContextSchema>;
161+
}
158162
: /**
159163
* If the context schema is all optional, `context` can be optional
160164
*/
161165
IsAllOptional<ContextSchema> extends true
162-
? Partial<Pick<PregelOptions<any, any, any>, CreateAgentPregelOptions>> & {
163-
context?: Partial<ContextSchema>;
164-
}
165-
: Partial<Pick<PregelOptions<any, any, any>, CreateAgentPregelOptions>> &
166+
? BaseCallbackConfig &
167+
Partial<
168+
Pick<PregelOptions<any, any, any>, CreateAgentPregelOptions>
169+
> & {
170+
context?: Partial<ContextSchema>;
171+
}
172+
: BaseCallbackConfig &
173+
Partial<Pick<PregelOptions<any, any, any>, CreateAgentPregelOptions>> &
166174
WithMaybeContext<ContextSchema>;
167175

168176
export type StreamConfiguration<ContextSchema extends Record<string, any>> =

libs/langchain/src/agents/tests/reactAgent.test-d.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,4 +189,30 @@ describe("reactAgent", () => {
189189
});
190190
});
191191
});
192+
193+
it("supports base callback config", async () => {
194+
const agent = createAgent({
195+
model: "openai:gpt-4",
196+
});
197+
await agent.invoke(
198+
{
199+
messages: [new HumanMessage("Hello, world!")],
200+
},
201+
{
202+
runName: "test",
203+
metadata: {
204+
test: "test",
205+
},
206+
callbacks: [
207+
{
208+
handleLLMStart: (input) => {
209+
expectTypeOf({ id: input.id }).toMatchObjectType<{
210+
id: string[];
211+
}>();
212+
},
213+
},
214+
],
215+
}
216+
);
217+
});
192218
});

0 commit comments

Comments
 (0)