Research Assistant¶
Overview¶
A minimal “web research assistant” that takes a single input topic, searches the
web using Tavily, and then synthesizes an answer with an LLM call. This example
demonstrates how to reuse OpenAPI-generated tools via references and bind tool
outputs into an LLM prompt.
Architecture¶
flowchart TD
subgraph APP ["📱 research_assistant"]
direction TB
subgraph FLOW_0 ["🔄 research"]
direction TB
FLOW_0_START@{shape: circle, label: "▶️ Start"}
FLOW_0_S0@{shape: rect, label: "⚙️ search_web"}
FLOW_0_S1@{shape: doc, label: "📄 build_prompt"}
FLOW_0_S2@{shape: rounded, label: "✨ synthesize"}
FLOW_0_START -->|topic| FLOW_0_S0
FLOW_0_START -->|topic| FLOW_0_S1
FLOW_0_S0 -->|tavily_results| FLOW_0_S1
FLOW_0_S1 -->|synthesis_prompt| FLOW_0_S2
end
subgraph RESOURCES ["🔧 Shared Resources"]
direction LR
AUTH_TAVILY_API_BEARERAUTH_TOKEN@{shape: hex, label: "🔐 tavily-api_bearerauth_token (BEARER_TOKEN)"}
MODEL_NOVA_LITE@{shape: rounded, label: "✨ nova_lite (aws-bedrock)" }
TOOL_SEARCH["⚡ search (POST)"]
TOOL_SEARCH -.->|uses| AUTH_TAVILY_API_BEARERAUTH_TOKEN
end
end
FLOW_0_S0 -.->|uses| TOOL_SEARCH
FLOW_0_S2 -.->|uses| MODEL_NOVA_LITE
%% Styling
classDef appBox fill:none,stroke:#495057,stroke-width:3px
classDef flowBox fill:#e1f5fe,stroke:#0277bd,stroke-width:2px
classDef llmNode fill:#f3e5f5,stroke:#7b1fa2,stroke-width:2px
classDef modelNode fill:#e8f5e8,stroke:#2e7d32,stroke-width:2px
classDef authNode fill:#fff3e0,stroke:#ef6c00,stroke-width:2px
classDef telemetryNode fill:#fce4ec,stroke:#c2185b,stroke-width:2px
classDef resourceBox fill:#f5f5f5,stroke:#616161,stroke-width:1px
class APP appBox
class FLOW_0 flowBox
class RESOURCES resourceBox
class TELEMETRY telemetryNode
Complete Code¶
# Research Assistant Example
#
# Takes one input (topic), searches the web via Tavily, then synthesizes
# an answer using an LLM call.
#
# Prereqs:
# - Set `TAVILY-API_BEARER` for Tavily auth (see tavily.qtype.yaml)
# - Configure AWS credentials if using Bedrock (default model below)
#
# Run with:
# qtype run \
# -i '{"topic":"Latest developments in retrieval augmented generation"}' \
# examples/research_assistant/research_assistant.qtype.yaml
id: research_assistant
description: Web search + synthesis research assistant using Tavily
# Import Tavily tools created from tavily.oas.yaml
references:
- !include ./tavily.qtype.yaml
models:
- type: Model
id: nova_lite
provider: aws-bedrock
model_id: amazon.nova-lite-v1:0
inference_params:
temperature: 0.3
max_tokens: 900
flows:
- type: Flow
id: research
description: Search the web for a topic and synthesize an answer
inputs:
- topic
outputs:
- answer
variables:
- id: topic
type: text
# Tavily outputs
- id: tavily_results
type:
element_type: schema_4844016144
# LLM prompt + response
- id: synthesis_prompt
type: text
- id: answer
type: text
steps:
- type: InvokeTool
id: search_web
tool: search
input_bindings:
query: topic
output_bindings:
results: tavily_results
outputs:
- tavily_results
- type: PromptTemplate
id: build_prompt
template: |
Research topic: {topic}
Search results (list of objects with url/content/score):
{tavily_results}
Task:
- Write a concise, well-structured answer to the research topic.
- If the results contain URLs, include 3-8 bullet citations at the end
using the URLs you relied on most.
- If information is missing or uncertain, say so explicitly.
inputs:
- topic
- tavily_results
outputs:
- synthesis_prompt
- type: LLMInference
id: synthesize
model: nova_lite
system_message: |
You are a careful research assistant. Use the provided search results.
Prefer accurate summaries over speculation.
inputs:
- synthesis_prompt
outputs:
- answer
Key Features¶
references(Application): Imports external QType documents (here, the Tavily tool library) so you can reference tools likesearchby IDBearerTokenAuthProvider.token: Stores the Tavily API key as a bearer token, loaded via${TAVILY-API_BEARER}environment-variable substitution- APITool: Represents the Tavily HTTP endpoints (like
/search) as typed tools with declaredinputsandoutputs - InvokeTool Step: Calls the
searchtool and maps flow variables to tool parameters viainput_bindings/output_bindings - PromptTemplate Step: Builds the synthesis prompt by combining the user topic and the Tavily search results
- LLMInference Step: Produces the final
answerby running model inference using the prompt produced byPromptTemplate
Running the Example¶
1) Create a Tavily account + API key¶
Create an account at Tavily and generate an API key.
2) Set the Tavily token in a .env¶
Create a .env file next to examples/research_assistant/research_assistant.qtype.yaml:
QType automatically loads a .env file from the spec’s directory when you run
qtype run.
3) Run¶
# Validate the YAML
qtype validate examples/research_assistant/research_assistant.qtype.yaml
# Run directly
qtype run -i '{"topic":"Latest developments in retrieval augmented generation"}' \
examples/research_assistant/research_assistant.qtype.yaml
Example Output¶
When running with the topic "Latest developments in retrieval augmented generation", the research assistant produces:
Latest Developments in Retrieval-Augmented Generation¶
Retrieval-Augmented Generation (RAG) has seen significant advancements, particularly in enhancing the accuracy and factual grounding of AI-generated content. Recent developments focus on improving the retrieval–generation pipeline, reducing hallucinations, and increasing performance metrics. For instance, performance improvements from 68% to 73% have been reported, with notable reductions in hallucinations and stronger factual grounding.
Key areas of progress include:
- Enhanced Retrieval Mechanisms: Improved algorithms for retrieving relevant information from large datasets.
- Stronger Factual Grounding: Techniques that ensure generated content is more accurate and grounded in factual data.
- Reduction of Hallucinations: Methods to minimize the generation of incorrect or misleading information.
- Targeted Enhancements: Specific improvements across different stages of the retrieval–generation process.
These advancements are expected to have a substantial impact on various applications, including natural language processing, content creation, and information retrieval systems.
Sources:
Learn More¶
- How-To: Create Tools from OpenAPI Specifications
- How-To: Bind Tool Inputs and Outputs
- How-To: Include QType YAML
- How-To: Call Large Language Models