///
import {
Cell,
computed,
generateObject,
NAME,
pattern,
patternTool,
str,
toSchema,
UI,
} from "commontools";
import { readWebpage, searchWeb } from "./system/common-tools.tsx";
type ResearchResult = {
/** Concise answer to the research question */
summary: string;
/** Key findings from the research */
findings: {
title: string;
source: string;
content: string;
}[];
/** List of URLs consulted */
sources: string[];
/** Confidence level in the answer */
confidence: "high" | "medium" | "low";
};
export default pattern<
{ question: string; context?: { [id: string]: any } },
{
question: string;
result: Cell;
pending: boolean;
error: string | undefined;
}
>(({ question, context }) => {
const research = generateObject({
system:
`You are a deep research agent. Given a question, use the available tools to:
1. Search the web for relevant information
2. Read promising web pages to gather detailed content
3. Synthesize your findings into a comprehensive answer
Be thorough - search for multiple aspects of the question and read several sources before forming your answer.`,
prompt: question,
context,
tools: {
searchWeb: patternTool(searchWeb),
readWebpage: patternTool(readWebpage),
},
schema: toSchema(),
model: "anthropic:claude-sonnet-4-5",
});
return {
[NAME]: str`Research: ${question}`,
result: research.result,
pending: research.pending,
error: research.error,
question,
[UI]: (