Skip to content

Add Finance Agent Example #1752

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Apr 14, 2025
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
8ff6f81
set up structure for FinanceAgent example
minmin-intel Mar 12, 2025
edfafe7
add tools and readme
minmin-intel Mar 12, 2025
94f16ef
add dataprep compose yaml
minmin-intel Mar 14, 2025
acf9796
add test scripts
minmin-intel Mar 14, 2025
00592bd
finqa and supervisor agent tested
minmin-intel Mar 14, 2025
2c20109
Summarization agent and updated supervisor (#1722)
rbrugaro Mar 27, 2025
434bbdf
fix summarization tool error
minmin-intel Apr 2, 2025
2fa357c
Add financial research agent. (#1738)
lkk12014402 Apr 3, 2025
3efd1f4
Merge branch 'main' into fin-agent-v1.3
minmin-intel Apr 3, 2025
8567ec6
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 3, 2025
ce604d1
update research agent prompt and tool.
lkk12014402 Apr 7, 2025
4a90551
update research agent tools and prompt.
lkk12014402 Apr 9, 2025
dfbd7a7
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 9, 2025
0363ad8
update ut.
lkk12014402 Apr 10, 2025
2a9b58a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 10, 2025
3a2068b
set missing env var
rbrugaro Apr 10, 2025
b599fdc
README edits
rbrugaro Apr 10, 2025
9d33629
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 10, 2025
e6ed987
update readme
minmin-intel Apr 11, 2025
727584c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 11, 2025
69c2d89
Merge branch 'main' into fin-agent-v1.3
lkk12014402 Apr 11, 2025
baa827b
add ui doc.
lkk12014402 Apr 11, 2025
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
71 changes: 71 additions & 0 deletions FinanceAgent/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Finance Agent

## 1. Overview

## 2. Getting started

### 2.1 Download repos

```bash
mkdir /path/to/your/workspace/
export WORKDIR=/path/to/your/workspace/
genaicomps
genaiexamples
```

### 2.2 Set up env vars

```bash
export HF_CACHE_DIR=/path/to/your/model/cache/
export HF_TOKEN=<you-hf-token>

```

### 2.3 Build docker images

Build docker images for dataprep, agent, agent-ui.

```bash
# use docker image build
```

If deploy on Gaudi, also need to build vllm image.

```bash
cd $WORKDIR
git clone https://github.com/HabanaAI/vllm-fork.git
# get the latest release tag of vllm gaudi
cd vllm-fork
VLLM_VER=$(git describe --tags "$(git rev-list --tags --max-count=1)")
echo "Check out vLLM tag ${VLLM_VER}"
git checkout ${VLLM_VER}
docker build --no-cache -f Dockerfile.hpu -t opea/vllm-gaudi:latest --shm-size=128g . --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy
```

## 3. Deploy with docker compose

### 3.1 Launch vllm endpoint

Below is the command to launch a vllm endpoint on Gaudi that serves `meta-llama/Llama-3.3-70B-Instruct` model on 4 Gaudi cards.

```bash
export vllm_port=8086
export vllm_volume=$HF_CACHE_DIR
export max_length=16384
export model="meta-llama/Llama-3.3-70B-Instruct"
docker run -d --runtime=habana --rm --name "vllm-gaudi-server" -e HABANA_VISIBLE_DEVICES=all -p $vllm_port:8000 -v $vllm_volume:/data -e HF_TOKEN=$HF_TOKEN -e HUGGING_FACE_HUB_TOKEN=$HF_TOKEN -e HF_HOME=/data -e OMPI_MCA_btl_vader_single_copy_mechanism=none -e PT_HPU_ENABLE_LAZY_COLLECTIVES=true -e http_proxy=$http_proxy -e https_proxy=$https_proxy -e no_proxy=$no_proxy -e VLLM_SKIP_WARMUP=true --cap-add=sys_nice --ipc=host opea/vllm-gaudi:comps --model ${model} --max-seq-len-to-capture $max_length --tensor-parallel-size 4
```

### 3.2 Prepare knowledge base

The commands below will upload some example files into the knowledge base. You can also upload files through UI.

First, launch the redis databases and the dataprep microservice.

```bash
docker compose -f $WORKDIR/GenAIExamples/FinanceAgent/docker_compose/intel/hpu/gaudi/dataprep_compose.yaml up -d
```

### 3.3 Launch the multi-agent system

### 3.4 Validate agents
121 changes: 121 additions & 0 deletions FinanceAgent/docker_compose/intel/hpu/gaudi/compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

services:
worker-finqa-agent:
image: opea/agent:latest
container_name: finqa-agent-endpoint
volumes:
- ${TOOLSET_PATH}:/home/user/tools/
- ${PROMPT_PATH}:/home/user/prompts/
ports:
- "9095:9095"
ipc: host
environment:
ip_address: ${ip_address}
strategy: react_llama
with_memory: false
recursion_limit: ${recursion_limit_worker}
llm_engine: vllm
HUGGINGFACEHUB_API_TOKEN: ${HUGGINGFACEHUB_API_TOKEN}
llm_endpoint_url: ${LLM_ENDPOINT_URL}
model: ${LLM_MODEL_ID}
temperature: ${TEMPERATURE}
max_new_tokens: ${MAX_TOKENS}
stream: false
tools: /home/user/tools/finqa_agent_tools.yaml
custom_prompt: /home/user/prompts/finqa_prompt.py
require_human_feedback: false
no_proxy: ${no_proxy}
http_proxy: ${http_proxy}
https_proxy: ${https_proxy}
REDIS_URL_VECTOR: $REDIS_URL_VECTOR
REDIS_URL_KV: $REDIS_URL_KV
TEI_EMBEDDING_ENDPOINT: $TEI_EMBEDDING_ENDPOINT
port: 9095

worker-research-agent:
image: opea/agent:latest
container_name: research-agent-endpoint
volumes:
- ${TOOLSET_PATH}:/home/user/tools/
- ${PROMPT_PATH}:/home/user/prompts/
ports:
- "9096:9096"
ipc: host
environment:
ip_address: ${ip_address}
strategy: react_llama
with_memory: false
recursion_limit: ${recursion_limit_worker}
llm_engine: vllm
HUGGINGFACEHUB_API_TOKEN: ${HUGGINGFACEHUB_API_TOKEN}
llm_endpoint_url: ${LLM_ENDPOINT_URL}
model: ${LLM_MODEL_ID}
stream: false
tools: /home/user/tools/research_agent_tools.yaml
custom_prompt: /home/user/prompts/research_prompt.py
require_human_feedback: false
no_proxy: ${no_proxy}
http_proxy: ${http_proxy}
https_proxy: ${https_proxy}
FINNHUB_API_KEY: ${FINNHUB_API_KEY}
FINANCIAL_DATASETS_API_KEY: ${FINANCIAL_DATASETS_API_KEY}
port: 9096

supervisor-react-agent:
image: opea/agent:latest
container_name: supervisor-agent-endpoint
depends_on:
- worker-finqa-agent
# - worker-research-agent
volumes:
- ${TOOLSET_PATH}:/home/user/tools/
- ${PROMPT_PATH}:/home/user/prompts/
ports:
- "9090:9090"
ipc: host
environment:
ip_address: ${ip_address}
strategy: react_llama
with_memory: true
recursion_limit: ${recursion_limit_supervisor}
llm_engine: vllm
HUGGINGFACEHUB_API_TOKEN: ${HUGGINGFACEHUB_API_TOKEN}
llm_endpoint_url: ${LLM_ENDPOINT_URL}
model: ${LLM_MODEL_ID}
temperature: ${TEMPERATURE}
max_new_tokens: ${MAX_TOKENS}
stream: true
tools: /home/user/tools/supervisor_agent_tools.yaml
custom_prompt: /home/user/prompts/supervisor_prompt.py
require_human_feedback: false
no_proxy: ${no_proxy}
http_proxy: ${http_proxy}
https_proxy: ${https_proxy}
WORKER_FINQA_AGENT_URL: $WORKER_FINQA_AGENT_URL
WORKER_RESEARCH_AGENT_URL: $WORKER_RESEARCH_AGENT_URL
DOCSUM_ENDPOINT: $DOCSUM_ENDPOINT
REDIS_URL_VECTOR: $REDIS_URL_VECTOR
REDIS_URL_KV: $REDIS_URL_KV
TEI_EMBEDDING_ENDPOINT: $TEI_EMBEDDING_ENDPOINT
port: 9090

docsum-vllm-gaudi:
image: opea/llm-docsum:latest
container_name: docsum-vllm-gaudi
ports:
- ${DOCSUM_PORT:-9000}:9000
ipc: host
environment:
no_proxy: ${no_proxy}
http_proxy: ${http_proxy}
https_proxy: ${https_proxy}
LLM_ENDPOINT: ${LLM_ENDPOINT}
LLM_MODEL_ID: ${LLM_MODEL_ID}
HF_TOKEN: ${HF_TOKEN}
LOGFLAG: ${LOGFLAG:-False}
MAX_INPUT_TOKENS: ${MAX_INPUT_TOKENS}
MAX_TOTAL_TOKENS: ${MAX_TOTAL_TOKENS}
DocSum_COMPONENT_NAME: ${DocSum_COMPONENT_NAME:-OpeaDocSumvLLM}
restart: unless-stopped
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Copyright (C) 2025 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

services:
tei-embedding-serving:
image: ghcr.io/huggingface/text-embeddings-inference:cpu-1.5
container_name: tei-embedding-serving
entrypoint: /bin/sh -c "apt-get update && apt-get install -y curl && text-embeddings-router --json-output --model-id ${EMBEDDING_MODEL_ID} --auto-truncate"
ports:
- "${TEI_EMBEDDER_PORT:-10221}:80"
volumes:
- "./data:/data"
shm_size: 1g
environment:
no_proxy: ${no_proxy}
http_proxy: ${http_proxy}
https_proxy: ${https_proxy}
host_ip: ${host_ip}
HF_TOKEN: ${HF_TOKEN}
healthcheck:
test: ["CMD", "curl", "-f", "http://${host_ip}:${TEI_EMBEDDER_PORT}/health"]
interval: 10s
timeout: 6s
retries: 48

redis-vector-db:
image: redis/redis-stack:7.2.0-v9
container_name: redis-vector-db
ports:
- "${REDIS_PORT1:-6379}:6379"
- "${REDIS_PORT2:-8001}:8001"
environment:
- no_proxy=${no_proxy}
- http_proxy=${http_proxy}
- https_proxy=${https_proxy}
healthcheck:
test: ["CMD", "redis-cli", "ping"]
timeout: 10s
retries: 3
start_period: 10s

redis-kv-store:
image: redis/redis-stack:7.2.0-v9
container_name: redis-kv-store
ports:
- "${REDIS_PORT3:-6380}:6379"
- "${REDIS_PORT4:-8002}:8001"
environment:
- no_proxy=${no_proxy}
- http_proxy=${http_proxy}
- https_proxy=${https_proxy}
healthcheck:
test: ["CMD", "redis-cli", "ping"]
timeout: 10s
retries: 3
start_period: 10s

dataprep-redis-finance:
image: ${REGISTRY:-opea}/dataprep:${TAG:-latest}
container_name: dataprep-redis-server-finance
depends_on:
redis-vector-db:
condition: service_healthy
redis-kv-store:
condition: service_healthy
tei-embedding-serving:
condition: service_healthy
ports:
- "${DATAPREP_PORT:-6007}:5000"
environment:
no_proxy: ${no_proxy}
http_proxy: ${http_proxy}
https_proxy: ${https_proxy}
DATAPREP_COMPONENT_NAME: ${DATAPREP_COMPONENT_NAME}
REDIS_URL_VECTOR: ${REDIS_URL_VECTOR}
REDIS_URL_KV: ${REDIS_URL_KV}
TEI_EMBEDDING_ENDPOINT: ${TEI_EMBEDDING_ENDPOINT}
LLM_ENDPOINT: ${LLM_ENDPOINT}
LLM_MODEL: ${LLM_MODEL}
HUGGINGFACEHUB_API_TOKEN: ${HF_TOKEN}
HF_TOKEN: ${HF_TOKEN}
LOGFLAG: true
36 changes: 36 additions & 0 deletions FinanceAgent/docker_compose/intel/hpu/gaudi/launch_agents.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

# Copyright (C) 2025 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

export ip_address=$(hostname -I | awk '{print $1}')
export HUGGINGFACEHUB_API_TOKEN=${HF_TOKEN}
export TOOLSET_PATH=$WORKDIR/GenAIExamples/FinanceAgent/tools/
echo "TOOLSET_PATH=${TOOLSET_PATH}"
export PROMPT_PATH=$WORKDIR/GenAIExamples/FinanceAgent/prompts/
echo "PROMPT_PATH=${PROMPT_PATH}"
export recursion_limit_worker=12
export recursion_limit_supervisor=10

vllm_port=8086
export LLM_MODEL_ID="meta-llama/Llama-3.3-70B-Instruct"
export LLM_ENDPOINT_URL="http://${ip_address}:${vllm_port}"
export TEMPERATURE=0.5
export MAX_TOKENS=4096

export WORKER_FINQA_AGENT_URL="http://${ip_address}:9095/v1/chat/completions"
export WORKER_RESEARCH_AGENT_URL="http://${ip_address}:9096/v1/chat/completions"

export EMBEDDING_MODEL_ID="BAAI/bge-base-en-v1.5"
export TEI_EMBEDDING_ENDPOINT="http://${ip_address}:10221"
export REDIS_URL_VECTOR="redis://${ip_address}:6379"
export REDIS_URL_KV="redis://${ip_address}:6380"

export MAX_INPUT_TOKENS=2048
export MAX_TOTAL_TOKENS=4096
export DocSum_COMPONENT_NAME="OpeaDocSumvLLM"
export DOCSUM_ENDPOINT="http://${ip_address}:9000/v1/docsum"

export FINNHUB_API_KEY=${FINNHUB_API_KEY}
export FINANCIAL_DATASETS_API_KEY=${FINANCIAL_DATASETS_API_KEY}

docker compose -f compose.yaml up -d
28 changes: 28 additions & 0 deletions FinanceAgent/docker_image_build/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

services:
dataprep:
build:
context: GenAIComps
dockerfile: comps/dataprep/src/Dockerfile
args:
http_proxy: ${http_proxy}
https_proxy: ${https_proxy}
no_proxy: ${no_proxy}
image: ${REGISTRY:-opea}/dataprep:${TAG:-latest}
agent:
build:
context: GenAIComps
dockerfile: comps/agent/src/Dockerfile
args:
http_proxy: ${http_proxy}
https_proxy: ${https_proxy}
no_proxy: ${no_proxy}
image: ${REGISTRY:-opea}/agent:${TAG:-latest}
# agent-ui:
# build:
# context: ../ui
# dockerfile: ./docker/Dockerfile
# extends: agent
# image: ${REGISTRY:-opea}/agent-ui:${TAG:-latest}
40 changes: 40 additions & 0 deletions FinanceAgent/prompts/finqa_prompt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright (C) 2025 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

REACT_AGENT_LLAMA_PROMPT = """\
You are a helpful assistant engaged in multi-turn conversations with Financial analysts.
You have access to the following two tools:
{tools}

**Procedure:**
1. Read the question carefully. Divide the question into sub-questions and conquer sub-questions one by one.
3. If there is execution history, read it carefully and reason about the information gathered so far and decide if you can answer the question or if you need to call more tools.

**Output format:**
You should output your thought process. Finish thinking first. Output tool calls or your answer at the end.
When making tool calls, you should use the following format:
TOOL CALL: {{"tool": "tool1", "args": {{"arg1": "value1", "arg2": "value2", ...}}}}

If you can answer the question, provide the answer in the following format:
FINAL ANSWER: {{"answer": "your answer here"}}


======= Conversations with user in previous turns =======
{thread_history}
======= End of previous conversations =======

======= Your execution History in this turn =========
{history}
======= End of execution history ==========

**Tips:**
* You may need to do multi-hop calculations and call tools multiple times to get an answer.
* Do not assume any financial figures. Always rely on the tools to get the factual information.
* If you need a certain financial figure, search for the figure instead of the financial statement name.
* If you did not get the answer at first, do not give up. Reflect on the steps that you have taken and try a different way. Think out of the box. You hard work will be rewarded.
* Give concise, factual and relevant answers.
* If the user question is too ambiguous, ask for clarification.

Now take a deep breath and think step by step to answer user's question in this turn.
USER MESSAGE: {input}
"""
Loading
Loading