Skip to content
Open
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
1 change: 1 addition & 0 deletions src/core/agent-as-tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export function agentAsTool<Ctx, Out = any>(
maxTurns,
// Memory isolation by default
...(memoryMode === 'none' ? { memory: undefined, conversationId: undefined } : {}),
preferStreaming: parentConfig.preferStreaming,
onEvent: (event) => {
if (propagateEvents === 'all') {
parentConfig.onEvent?.(event);
Expand Down
12 changes: 8 additions & 4 deletions src/core/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -496,10 +496,12 @@ async function runInternal<Ctx, Out>(
llmResponse = await config.modelProvider.getCompletion(state, currentAgent, config);
}
} else {
if (typeof config.modelProvider.getCompletionStream === 'function') {
const getStream = config.modelProvider.getCompletionStream;
const useStreaming = config.preferStreaming !== false && typeof getStream === 'function';
if (useStreaming) {
try {
streamingUsed = true;
const stream = config.modelProvider.getCompletionStream(state, currentAgent, config);
const stream = getStream(state, currentAgent, config);
let aggregatedText = '';
const toolCalls: Array<{ id?: string; type: 'function'; function: { name?: string; arguments: string } }> = [];

Expand Down Expand Up @@ -569,10 +571,12 @@ async function runInternal<Ctx, Out>(
}
}
} else {
if (typeof config.modelProvider.getCompletionStream === 'function') {
const getStream = config.modelProvider.getCompletionStream;
const useStreaming = config.preferStreaming !== false && typeof getStream === 'function';
if (useStreaming) {
try {
streamingUsed = true;
const stream = config.modelProvider.getCompletionStream(state, currentAgent, config);
const stream = getStream(state, currentAgent, config);
let aggregatedText = '';
const toolCalls: Array<{ id?: string; type: 'function'; function: { name?: string; arguments: string } }> = [];

Expand Down
3 changes: 2 additions & 1 deletion src/core/guardrails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,8 @@ ${sanitizedContent}
modelOverride: modelToUse,
initialInputGuardrails: undefined,
finalOutputGuardrails: undefined,
onEvent: undefined
onEvent: undefined,
preferStreaming: config.preferStreaming
};

const completionPromise = config.modelProvider.getCompletion(tempState, evalAgent, guardrailConfig);
Expand Down
1 change: 1 addition & 0 deletions src/core/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ export type RunConfig<Ctx> = {
readonly conversationId?: string;
readonly approvalStorage?: ApprovalStorage;
readonly defaultFastModel?: string;
readonly preferStreaming?: boolean;
};

export const jsonParseLLMOutput = (text: string): any => {
Expand Down
9 changes: 7 additions & 2 deletions src/providers/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,14 @@ export const makeLiteLLMProvider = <Ctx>(
async getCompletion(state, agent, config) {
const { model, params } = await buildChatCompletionParams(state, agent, config, baseURL);

safeConsole.log(`📞 Calling model: ${model} with params: ${JSON.stringify(params, null, 2)}`);
const requestParams = {
...params,
stream: false,
};

safeConsole.log(`📞 Calling model: ${model} with params: ${JSON.stringify(requestParams, null, 2)}`);
const resp = await client.chat.completions.create(
params as OpenAI.Chat.Completions.ChatCompletionCreateParamsNonStreaming
requestParams as OpenAI.Chat.Completions.ChatCompletionCreateParamsNonStreaming
);

// Return the choice with usage data attached for tracing
Expand Down