Refine onboarding state and nickname checks
This commit is contained in:
1 parent
5579db54da
commit
9c013f7d4f
33 files changed
+1523
-119
No files matched your search
@@ -1,4 +1,5 @@
|
||||
import { withToolSpan } from "@obs/spans";
|
||||
import { getRequestLogger } from "@obs/context";
|
||||
import type { LlmClient } from "@llm/llm-client";
|
||||
import type { ChatCompletionOptions, ChatMessage } from "@llm/types";
|
||||
import { parseToolCalls } from "@tools/parser";
|
||||
@@ -22,6 +23,7 @@ export interface ToolLoopOptions {
|
||||
export async function runWithTools(
|
||||
options: ToolLoopOptions,
|
||||
): Promise<string | null> {
|
||||
const logger = getRequestLogger();
|
||||
const maxHops = options.maxHops ?? 2;
|
||||
const messages = options.messages.map((message) => ({ ...message }));
|
||||
let allowNativeTools = true;
|
||||
@@ -39,14 +41,44 @@ export async function runWithTools(
|
||||
});
|
||||
|
||||
if (!response) {
|
||||
logger.debug(
|
||||
{
|
||||
hop,
|
||||
role: options.role,
|
||||
tier: options.tier,
|
||||
},
|
||||
"[ToolLoop] LLM returned no response",
|
||||
);
|
||||
return null;
|
||||
}
|
||||
|
||||
const toolCalls = parseToolCalls(response.message);
|
||||
if (toolCalls.length === 0) {
|
||||
logger.debug(
|
||||
{
|
||||
content: response.content,
|
||||
hop,
|
||||
role: options.role,
|
||||
tier: options.tier,
|
||||
},
|
||||
"[ToolLoop] No tool call in model response",
|
||||
);
|
||||
return response.content;
|
||||
}
|
||||
|
||||
logger.debug(
|
||||
{
|
||||
hop,
|
||||
role: options.role,
|
||||
tier: options.tier,
|
||||
toolCalls: toolCalls.map((call) => ({
|
||||
id: call.id,
|
||||
name: call.name,
|
||||
})),
|
||||
},
|
||||
"[ToolLoop] Parsed tool calls",
|
||||
);
|
||||
|
||||
if (hop === maxHops) {
|
||||
messages.push(response.message);
|
||||
messages.push({
|
||||
@@ -66,6 +98,15 @@ export async function runWithTools(
|
||||
throw new Error(`Tool not registered for call: ${call.name}`);
|
||||
}
|
||||
|
||||
logger.debug(
|
||||
{
|
||||
arguments: call.arguments,
|
||||
callId: call.id,
|
||||
tool: tool.name,
|
||||
},
|
||||
"[ToolLoop] Executing tool call",
|
||||
);
|
||||
|
||||
const validated = tool.argsSchema.parse(call.arguments);
|
||||
const result = await withToolSpan(
|
||||
tool.name,
|
||||
@@ -76,6 +117,15 @@ export async function runWithTools(
|
||||
() => tool.execute(validated, options.toolContext),
|
||||
);
|
||||
|
||||
logger.debug(
|
||||
{
|
||||
callId: call.id,
|
||||
result,
|
||||
tool: tool.name,
|
||||
},
|
||||
"[ToolLoop] Tool call completed",
|
||||
);
|
||||
|
||||
messages.push({
|
||||
role: "tool",
|
||||
name: tool.name,
|
||||
|
||||
Reference in new issue
Block a user