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
29 changes: 29 additions & 0 deletions examples/scientific-research.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Swarm } from "../core";
import { scientificAgent } from "../agents/scientist";

/**
* DEMO: Scientific Research Synthesis
* This example demonstrates the RAG pipeline retrieving peer-reviewed
* papers and generating a cited response.
*/
async function runResearchDemo() {
const swarm = new Swarm();
const query = "What are the latest findings on using Metformin for lifespan extension in non-diabetics?";

console.log(`\n🔬 Topic: ${query}`);
console.log("--------------------------------------------------\n");
console.log("Searching scientific databases... 🛰️\n");

const messages = [{ role: "user", content: query }];

// Execute the Swarm loop with the Scientific Agent
const response = await swarm.run({
agent: scientificAgent,
messages: messages,
});

console.log("RESEARCH SYNTHESIS:\n");
console.log(response.messages[response.messages.length - 1].content);
}

runResearchDemo().catch(console.error);
1 change: 1 addition & 0 deletions src/agents/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './scientist';
21 changes: 21 additions & 0 deletions src/agents/scientist.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Agent } from "../core";
import { fetch_papers, fetch_papers_descriptor } from "../tools/research";

/**
* The Scientific Researcher Agent
* Specialized in deep literature review and academic synthesis.
*/
export const scientificAgent = new Agent({
name: "Scientific Researcher",
instructions: `You are an Elite Scientific Researcher. Your goal is to provide accurate, evidence-based answers using the provided scientific literature tools.

OPERATING GUIDELINES:
1. ALWAYS use the 'fetch_papers' tool for any technical, medical, or scientific queries.
2. CITATIONS: Every factual claim MUST be followed by a citation in brackets, e.g., [1].
3. SOURCES: At the end of your response, list the 'References' with their full URLs.
4. RIGOR: If the retrieved papers do not support a claim, state that the evidence is inconclusive.
5. NO HALLUCINATIONS: Do not invent papers or facts. If 'fetch_papers' returns no results, admit it.

Your tone should be professional, objective, and analytical.`,
functions: [fetch_papers_descriptor],
});
Loading