diff --git a/src/agent/extract-text.ts b/src/agent/extract-text.ts index 145a2c97..8075e61f 100644 --- a/src/agent/extract-text.ts +++ b/src/agent/extract-text.ts @@ -10,3 +10,14 @@ export function extractText(message: AgentMessage | undefined): string { .map((c) => c.text ?? "") .join(""); } + +/** Extract thinking/reasoning content from an AgentMessage */ +export function extractThinking(message: AgentMessage | undefined): string { + if (!message || typeof message !== "object" || !("content" in message)) return ""; + const content = (message as { content?: Array<{ type: string; thinking?: string }> }).content; + if (!Array.isArray(content)) return ""; + return content + .filter((c) => c.type === "thinking") + .map((c) => c.thinking ?? "") + .join(""); +} diff --git a/src/agent/profile/types.ts b/src/agent/profile/types.ts index f1de243d..f03f7d11 100644 --- a/src/agent/profile/types.ts +++ b/src/agent/profile/types.ts @@ -37,6 +37,8 @@ export interface ProfileConfig { model?: string; /** Default thinking level */ thinkingLevel?: string; + /** Reasoning mode: off, on, stream */ + reasoningMode?: "off" | "on" | "stream" | undefined; } /** Agent Profile configuration */ diff --git a/src/agent/session/types.ts b/src/agent/session/types.ts index c9086b74..72c810ab 100644 --- a/src/agent/session/types.ts +++ b/src/agent/session/types.ts @@ -4,6 +4,8 @@ export type SessionMeta = { provider?: string; model?: string; thinkingLevel?: string; + /** Reasoning mode: off, on, stream */ + reasoningMode?: string; /** Context window token 数 */ contextWindowTokens?: number; }; diff --git a/src/agent/types.ts b/src/agent/types.ts index c7e37658..6f7b7806 100644 --- a/src/agent/types.ts +++ b/src/agent/types.ts @@ -2,8 +2,13 @@ import type { ThinkingLevel } from "@mariozechner/pi-agent-core"; import type { SkillsConfig } from "./skills/types.js"; import type { ToolsConfig } from "./tools/policy.js"; +/** Controls how reasoning/thinking content blocks are handled */ +export type ReasoningMode = "off" | "on" | "stream"; + export type AgentRunResult = { text: string; + /** Extracted thinking/reasoning content (when reasoningMode !== "off") */ + thinking?: string | undefined; error?: string | undefined; }; @@ -28,6 +33,8 @@ export type AgentOptions = { /** System prompt, if profileId is set will auto-construct from profile */ systemPrompt?: string | undefined; thinkingLevel?: ThinkingLevel | undefined; + /** Controls how reasoning/thinking content is displayed: off, on, stream (default: stream) */ + reasoningMode?: ReasoningMode | undefined; /** Command execution directory */ cwd?: string | undefined; sessionId?: string | undefined;