Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions libs/langchain/src/agents/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type {
PregelOptions,
} from "@langchain/langgraph";
import type { BaseMessage } from "@langchain/core/messages";
import type { BaseCallbackConfig } from "@langchain/core/callbacks/manager";

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

Expand Down Expand Up @@ -152,17 +153,24 @@ export type InvokeConfiguration<ContextSchema extends Record<string, any>> =
* If the context schema is a default object, `context` can be optional
*/
ContextSchema extends InteropZodDefault<any>
? Partial<Pick<PregelOptions<any, any, any>, CreateAgentPregelOptions>> & {
context?: Partial<ContextSchema>;
}
? BaseCallbackConfig &
Partial<
Pick<PregelOptions<any, any, any>, CreateAgentPregelOptions>
> & {
context?: Partial<ContextSchema>;
}
: /**
* If the context schema is all optional, `context` can be optional
*/
IsAllOptional<ContextSchema> extends true
? Partial<Pick<PregelOptions<any, any, any>, CreateAgentPregelOptions>> & {
context?: Partial<ContextSchema>;
}
: Partial<Pick<PregelOptions<any, any, any>, CreateAgentPregelOptions>> &
? BaseCallbackConfig &
Partial<
Pick<PregelOptions<any, any, any>, CreateAgentPregelOptions>
> & {
context?: Partial<ContextSchema>;
}
: BaseCallbackConfig &
Partial<Pick<PregelOptions<any, any, any>, CreateAgentPregelOptions>> &
WithMaybeContext<ContextSchema>;

export type StreamConfiguration<ContextSchema extends Record<string, any>> =
Expand Down
26 changes: 26 additions & 0 deletions libs/langchain/src/agents/tests/reactAgent.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,30 @@ describe("reactAgent", () => {
});
});
});

it("supports base callback config", async () => {
const agent = createAgent({
model: "openai:gpt-4",
});
await agent.invoke(
{
messages: [new HumanMessage("Hello, world!")],
},
{
runName: "test",
metadata: {
test: "test",
},
callbacks: [
{
handleLLMStart: (input) => {
expectTypeOf({ id: input.id }).toMatchObjectType<{
id: string[];
}>();
},
},
],
}
);
});
});