feat(agent): add reasoning mode types and thinking extraction

Add ReasoningMode type (off/on/stream) to AgentOptions and related
config types. Add extractThinking() for extracting thinking content
blocks from LLM responses, mirroring the existing extractText() pattern.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
yushen 2026-02-04 15:50:35 +08:00
parent cea3336256
commit 77d5702f80
4 changed files with 22 additions and 0 deletions

View file

@ -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("");
}

View file

@ -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 */

View file

@ -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;
};

View file

@ -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;