Skip to content

Commit 30852c7

Browse files
committed
Transit DeepResearchAgent implementation
Signed-off-by: Joshua Yao <[email protected]>
1 parent 090d53a commit 30852c7

File tree

17 files changed

+968
-144
lines changed

17 files changed

+968
-144
lines changed

ChatQnA/docker_compose/intel/hpu/gaudi/compose.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ services:
109109
NUM_CARDS: ${NUM_CARDS}
110110
HF_HUB_OFFLINE: ${HF_HUB_OFFLINE:-0}
111111
VLLM_TORCH_PROFILER_DIR: "/mnt"
112+
VLLM_SKIP_WARMUP: true
112113
healthcheck:
113114
test: ["CMD-SHELL", "curl -f http://localhost:80/health || exit 1"]
114115
interval: 10s

DeepResearchAgent/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ ARG IMAGE_REPO=opea
55
ARG BASE_TAG=latest
66
FROM opea/comps-base:$BASE_TAG
77

8-
COPY ./deep_researcher.yaml $HOME/deep_researcher.yaml
9-
COPY ./utils.py $HOME/utils.py
8+
COPY ./research_agents $HOME/research_agents
109
COPY ./requirements.txt $HOME/requirements.txt
10+
COPY ./agent_factory.py $HOME/agent_factory.py
1111
COPY ./research_agent.py $HOME/research_agent.py
1212

1313
USER root

DeepResearchAgent/README.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,15 @@ Deep Research Agents are a new class of autonomous AI systems designed to perfor
44

55
## Overview
66

7-
In this application, we leverage the deep research agent implementation of [langchain-ai/open_deep_research](https://github.com/langchain-ai/open_deep_research), and deploy it on the Intel platform with opea microserice.
7+
In this application, we leverage the deep research agent implementation of [langchain-ai/deepagents](https://github.com/langchain-ai/deepagents), and deploy it on the Intel platform with opea microserice.
88

9-
![Architecture Overview](assets/img/opea-deep-research-agent.png)
109

1110
## Setup Deployment Environment
1211

13-
```
14-
# Configure deep_researcher.yaml with your llm model served by the vllm
15-
12+
```shell
1613
# get your TAVILY_API_KEY from https://app.tavily.com/
1714
export TAVILY_API_KEY=""
15+
1816
# get your HuggingFace Access Token from https://huggingface.co/docs/transformers.js/en/guides/private#step-1-generating-a-user-access-token
1917
export HF_TOKEN=""
2018

@@ -31,9 +29,8 @@ source ./set_env.sh
3129

3230
To deploy the Deep Research Agent services, execute the docker compose up command with the appropriate arguments. For a default deployment, execute:
3331

34-
```
32+
```shell
3533
docker compose -f docker_compose/intel/hpu/gaudi/compose.yaml up -d
36-
3734
```
3835

3936
## Validate Microservice

DeepResearchAgent/agent_factory.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import os
2+
from datetime import datetime
3+
from typing import Any
4+
from langchain_openai import ChatOpenAI
5+
6+
7+
def create_deepagents_research_agent() -> Any:
8+
from deepagents import create_deep_agent
9+
from research_agents.deepagents.prompts import (
10+
RESEARCHER_INSTRUCTIONS,
11+
RESEARCH_WORKFLOW_INSTRUCTIONS,
12+
SUBAGENT_DELEGATION_INSTRUCTIONS,
13+
)
14+
from research_agents.deepagents.tools import tavily_search, think_tool
15+
16+
# Limits
17+
max_concurrent_research_units = os.environ.get("MAX_CONCURRENT_RESEARCH_UNITS", 3)
18+
max_researcher_iterations = os.environ.get("MAX_RESEARCHER_ITERATIONS", 3)
19+
20+
# Custom instructions (if any)
21+
instructions_researcher=os.environ.get("RESEARCHER_INSTRUCTIONS", RESEARCHER_INSTRUCTIONS)
22+
instructions_research_workflow=os.environ.get("RESEARCH_WORKFLOW_INSTRUCTIONS", RESEARCH_WORKFLOW_INSTRUCTIONS)
23+
instructions_subagent_delegation=os.environ.get("SUBAGENT_DELEGATION_INSTRUCTIONS", SUBAGENT_DELEGATION_INSTRUCTIONS)
24+
25+
# Combine orchestrator instructions (RESEARCHER_INSTRUCTIONS only for sub-agents)
26+
INSTRUCTIONS = (
27+
instructions_research_workflow
28+
+ "\n\n"
29+
+ "=" * 80
30+
+ "\n\n"
31+
+ instructions_subagent_delegation.format(
32+
max_concurrent_research_units=max_concurrent_research_units,
33+
max_researcher_iterations=max_researcher_iterations,
34+
)
35+
)
36+
37+
# Get current date
38+
current_date = datetime.now().strftime("%Y-%m-%d")
39+
40+
# Research agent definition
41+
research_sub_agent = {
42+
"name": "research-agent",
43+
"description": "Delegate research to the sub-agent researcher. Only give this researcher one topic at a time.",
44+
"system_prompt": instructions_researcher.format(date=current_date),
45+
"tools": [tavily_search, think_tool],
46+
}
47+
48+
# LLM serving endpoint
49+
model = ChatOpenAI(
50+
openai_api_base=os.environ.get("OPENAI_BASE_URL", "http://0.0.0.0:8000/v1/"),
51+
openai_api_key=os.environ.get("OPENAI_API_KEY", "empty-api-key"),
52+
model_name=os.environ.get("LLM_MODEL_ID", "meta-llama/Llama-3.3-70B-Instruct"),
53+
temperature=0.0
54+
)
55+
56+
# Create the agent
57+
return create_deep_agent(
58+
model=model,
59+
tools=[tavily_search, think_tool],
60+
system_prompt=INSTRUCTIONS,
61+
subagents=[research_sub_agent],
62+
)
63+
64+
def create_agent(impl="DeepAgents") -> Any:
65+
if impl == "DeepAgents":
66+
return create_deepagents_research_agent()
67+
else:
68+
raise ValueError(f"Unknown agent implementation: {impl}")
-52.8 KB
Binary file not shown.

DeepResearchAgent/deep_researcher.yaml

Lines changed: 0 additions & 11 deletions
This file was deleted.

DeepResearchAgent/docker_compose/intel/hpu/gaudi/compose.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ services:
4545
cap_add:
4646
- SYS_NICE
4747
ipc: host
48-
command: --model ${LLM_MODEL_ID} --tensor-parallel-size ${NUM_CARDS} --host 0.0.0.0 --port 8000 --max-seq-len-to-capture $MAX_LEN
48+
command: --model ${LLM_MODEL_ID} --tensor-parallel-size ${NUM_CARDS} --enable-auto-tool-choice --tool-call-parser llama3_json --host 0.0.0.0 --port 8000 --max-seq-len-to-capture $MAX_LEN
4949

5050
deep-research-agent-server:
5151
image: ${REGISTRY:-opea}/deep-research-agent:${TAG:-latest}

DeepResearchAgent/docker_compose/intel/hpu/gaudi/set_env.sh

Lines changed: 75 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,45 +3,102 @@
33
# Copyright (C) 2024 Intel Corporation
44
# SPDX-License-Identifier: Apache-2.0
55

6-
# Navigate to the parent directory and source the environment
6+
# ==============================================================================
7+
# Environment Configuration for DeepResearchAgent on Intel Gaudi HPU
8+
# ==============================================================================
9+
10+
# Get the directory where this script is located
711
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &> /dev/null && pwd)"
812

13+
# Source the parent environment configuration file
914
pushd "$SCRIPT_DIR/../../../../../" > /dev/null
1015
source .set_env.sh
1116
popd > /dev/null
1217

13-
# Function to check if a variable is set
18+
# ------------------------------------------------------------------------------
19+
# Helper Functions
20+
# ------------------------------------------------------------------------------
21+
22+
# Validates that a required environment variable is set
1423
check_var() {
1524
local var_name="$1"
1625
local var_value="${!var_name}"
1726
if [ -z "${var_value}" ]; then
1827
echo "Error: ${var_name} is not set. Please set ${var_name}."
19-
return 1 # Return an error code but do not exit the script
28+
return 1 # Return error but don't exit to allow other checks to run
2029
fi
2130
}
2231

23-
# Check critical variables
24-
check_var "HF_TOKEN"
32+
# ------------------------------------------------------------------------------
33+
# Validate Required API Keys
34+
# ------------------------------------------------------------------------------
35+
36+
check_var "HF_TOKEN" # HuggingFace token for model access
37+
check_var "TAVILY_API_KEY" # Tavily API key for web search functionality
38+
39+
# ------------------------------------------------------------------------------
40+
# Network Configuration
41+
# ------------------------------------------------------------------------------
42+
43+
# Detect the primary IP address of the host machine
2544
export ip_address=$(hostname -I | awk '{print $1}')
45+
export HOST_IP=${ip_address}
2646

27-
# VLLM configuration
47+
# Update proxy settings to include the host IP
48+
export no_proxy=${no_proxy},${ip_address}
49+
export http_proxy=${http_proxy}
50+
export https_proxy=${https_proxy}
51+
52+
# ------------------------------------------------------------------------------
53+
# vLLM Service Configuration
54+
# ------------------------------------------------------------------------------
55+
56+
# Port where vLLM service will be accessible
2857
export VLLM_PORT="${VLLM_PORT:-8000}"
29-
export VLLM_VOLUME="${VLLM_VOLUME:-/data2/huggingface}"
30-
export VLLM_IMAGE="${VLLM_IMAGE:-opea/vllm-gaudi:latest}"
58+
59+
# ------------------------------------------------------------------------------
60+
# Language Model Configuration
61+
# ------------------------------------------------------------------------------
62+
63+
# LLM model to use for the Deep Research Agent
64+
# See supported models and tool call parsers at:
65+
# https://docs.vllm.ai/en/stable/features/tool_calling/#automatic-function-calling
3166
export LLM_MODEL_ID="${LLM_MODEL_ID:-meta-llama/Llama-3.3-70B-Instruct}"
67+
68+
# Parser for handling function/tool calls (must match the model)
69+
export TOOL_CALL_PARSER="${TOOL_CALL_PARSER:-llama3_json}"
70+
71+
# Maximum sequence length for model context (131072 = ~128K tokens)
3272
export MAX_LEN="${MAX_LEN:-131072}"
73+
74+
# Number of Gaudi accelerator cards to use
3375
export NUM_CARDS="${NUM_CARDS:-4}"
76+
77+
# Directory for caching HuggingFace models
3478
export HF_CACHE_DIR="${HF_CACHE_DIR:-"./data"}"
35-
export OPENAI_BASE_URL="http://${ip_address}:8000/v1"
36-
export OPENAI_API_KEY="empty"
37-
export no_proxy=${no_proxy}
38-
export http_proxy=${http_proxy}
39-
export https_proxy=${https_proxy}
4079

80+
# OpenAI-compatible API endpoint URL for vLLM
81+
export OPENAI_BASE_URL="http://${ip_address}:${VLLM_PORT}/v1"
82+
83+
# ------------------------------------------------------------------------------
84+
# API Keys and Authentication
85+
# ------------------------------------------------------------------------------
86+
87+
export HF_TOKEN="${HF_TOKEN}" # HuggingFace authentication token
88+
export OPENAI_API_KEY="empty-api-key" # Placeholder for vLLM compatibility
89+
export TAVILY_API_KEY="${TAVILY_API_KEY}" # Tavily search API key
90+
91+
# ------------------------------------------------------------------------------
92+
# Deep Research Agent Configuration
93+
# ------------------------------------------------------------------------------
94+
95+
# Maximum number of research units that can run concurrently
96+
export MAX_CONCURRENT_RESEARCH_UNITS="${MAX_CONCURRENT_RESEARCH_UNITS:-3}"
4197

42-
# Hugging Face API token
43-
export HF_TOKEN="${HF_TOKEN}"
98+
# Maximum iterations per researcher before stopping
99+
export MAX_RESEARCHER_ITERATIONS="${MAX_RESEARCHER_ITERATIONS:-3}"
44100

45-
# API keys
46-
check_var "TAVILY_API_KEY"
47-
export TAVILY_API_KEY="${TAVILY_API_KEY}"
101+
# Custom instructions for agent behavior (leave empty for defaults)
102+
export RESEARCHER_INSTRUCTIONS="" # Instructions for individual researchers
103+
export RESEARCH_WORKFLOW_INSTRUCTIONS="" # Instructions for overall research workflow
104+
export SUBAGENT_DELEGATION_INSTRUCTIONS="" # Instructions for task delegation between agents

DeepResearchAgent/requirements.in

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
deepagents
2+
httpx
3+
langchain_openai
4+
langchain-tavily
5+
langgraph-cli[inmem]
6+
markdownify
7+
rich
8+
tavily-python

0 commit comments

Comments
 (0)