> ## Documentation Index
> Fetch the complete documentation index at: https://docs.praison.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Research Assistant

> Multi-agent research workflow with web search, persistence, and API deployment

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
flowchart LR
    In[Research Topic] --> R[Researcher]
    R --> A[Gap Analyst]
    A --> D[Experiment Designer]
    D --> Out[Research Plan]
    
    style In fill:#8B0000,color:#fff
    style R fill:#2E8B57,color:#fff
    style A fill:#2E8B57,color:#fff
    style D fill:#2E8B57,color:#fff
    style Out fill:#8B0000,color:#fff
```

Multi-agent workflow: web search → gap analysis → experiment design → validation → impact prediction. Includes SQLite persistence, vector retrieval, observability, and API deployment.

## Setup

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
# Create environment
python3 -m venv venv && source venv/bin/activate

# Install packages
pip install praisonaiagents praisonai

# Set API keys
export OPENAI_API_KEY="your-key"
export TAVILY_API_KEY="your-key"  # For web search
```

## Run: Python Code

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
from praisonaiagents import Agent, AgentTeam, Task, tool
import json

# Database persistence is configured via memory={} parameter

# Web search tool
@tool
def search_papers(query: str) -> str:
    """Search for research papers on a topic."""
    from tavily import TavilyClient
    import os
    client = TavilyClient(api_key=os.getenv("TAVILY_API_KEY"))
    results = client.search(query, max_results=5)
    return json.dumps([{"title": r["title"], "url": r["url"], "content": r["content"][:200]} for r in results["results"]])

# Agents
researcher = Agent(
    name="Researcher",
    instructions="Search and analyze research papers on the given topic.",
    tools=[search_papers],
    memory={
        "db": "sqlite:///research.db",
        "session_id": "research-session"
    }
)

analyst = Agent(
    name="GapAnalyst", 
    instructions="Identify knowledge gaps from research findings."
)

designer = Agent(
    name="ExperimentDesigner",
    instructions="Design experiments to address identified gaps."
)

# Tasks
search_task = Task(
    description="Search for recent papers on: {topic}",
    agent=researcher,
    expected_output="List of relevant papers with summaries"
)

gap_task = Task(
    description="Analyze papers and identify 3 key research gaps",
    agent=analyst,
    expected_output="JSON with gaps: [{area, significance, potential}]"
)

design_task = Task(
    description="Design experiment for the highest-priority gap",
    agent=designer,
    expected_output="Experiment plan with methodology, resources, timeline"
)

# Run workflow
agents = AgentTeam(agents=[researcher, analyst, designer], tasks=[search_task, gap_task, design_task])
result = agents.start(topic="quantum error correction")
print(result)
```

## Run: CLI

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
# Single prompt
praisonai "Research quantum error correction and identify gaps" --tools --web-search

# With persistence
praisonai "Research AI safety" --memory --user-id researcher1

# With telemetry
praisonai "Research climate models" --telemetry --verbose
```

## Run: agents.yaml

Create `agents.yaml`:

```yaml theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
framework: praisonai
topic: "quantum error correction research"
roles:
  researcher:
    role: Research Analyst
    goal: Find and analyze recent research papers
    backstory: Expert at literature review and synthesis
    tools:
      - tavily_search
    tasks:
      search_papers:
        description: Search for papers on {topic}
        expected_output: List of 5 relevant papers with summaries
        
  analyst:
    role: Gap Analyst
    goal: Identify research gaps
    backstory: Expert at finding unexplored research areas
    tasks:
      find_gaps:
        description: Identify 3 key gaps from the research
        expected_output: JSON array of gaps with significance scores
        
  designer:
    role: Experiment Designer
    goal: Design experiments
    backstory: Expert at experimental methodology
    tasks:
      design_experiment:
        description: Design experiment for highest priority gap
        expected_output: Detailed experiment plan
```

Run:

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
praisonai agents.yaml --verbose
```

## Monitor & Verify

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
# View session history
praisonai --history 10 --user-id researcher1

# Check telemetry
praisonai --metrics

# Export results
praisonai --save research_results
```

## Serve API

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
# Start API server
praisonai --serve --port 8000
```

Test endpoint:

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
curl -X POST http://localhost:8000/api/v1/chat \
  -H "Content-Type: application/json" \
  -d '{"message": "Research quantum computing advances", "session_id": "api-session"}'
```

Or use Python SDK to serve:

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
from praisonaiagents import Agent

agent = Agent(
    name="ResearchAPI",
    instructions="Research assistant for scientific topics"
)
agent.launch(path="/research", port=8000)
```

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
curl -X POST http://localhost:8000/research \
  -H "Content-Type: application/json" \
  -d '{"message": "What are the latest advances in fusion energy?"}'
```

## Cleanup

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
rm -f research.db
deactivate
```

## Features Demonstrated

| Feature            | Implementation                  |
| ------------------ | ------------------------------- |
| **Multi-agent**    | 3 agents in sequential workflow |
| **Web Search**     | Tavily integration via `@tool`  |
| **DB Persistence** | SQLite via `db()`               |
| **Session Resume** | `session_id` parameter          |
| **CLI**            | `praisonai` with flags          |
| **YAML Config**    | `agents.yaml` format            |
| **API Endpoint**   | `agent.launch()`                |
| **Telemetry**      | `--telemetry` flag              |
