Skip to content

Commit 2fd0b40

Browse files
ansh-infogurdeep330
andauthoredJan 28, 2025··
feat: setup talk2comp (#67)
* feat: initialize agents package with main and s2 agent exports * feat: implement main supervisor agent with LangGraph routing * feat: add Semantic Scholar agent with ReAct pattern * feat: initialize Semantic Scholar tools package * feat: implement paper search tool with pagination * feat: add single paper recommendation tool * feat: implement multi-paper recommendation tool * feat: add results display formatting tool * feat: initialize utils package * feat: add LLM manager with OpenAI integration and tool binding * feat: initialize testing package * feat: add test configuration and fixtures * feat: implement comprehensive test suite for agents and tools * feat: add Streamlit configuration for UI customization * feat: implement Streamlit chat interface with session management * feat: add centralized configuration with system prompts and API settings * feat: implement shared state management for agent communication * fix: update * feat: update * chore: remove outdated streamlit application * chore: Ignored macOS specific metadata file * chore: Fixed zsh bad assignment error for OPENAI_API_KEY env variable * feat: Used Command instead of AIMessage for return and added year specifc search * feat: added year based search capabilities, and used Dict instead of list * feat: updated to use Dict instead of list for strcutured ouput * fix: updated the system prompts * fix: string length for pylint test * fix: added Unit and integration tests for Talk2Competitors * fix: __init__ paths for PyPI * fix: __init__ paths for PyPI * feat: tutorial for talk2competitors * feat: tools documentation for MkDocs * feat: state documentation for MkDocs * feat: agents documentation for MkDocs * feat: Introduction documentation for Talk2Competitors * feat: MkDocs documentation for Talk2Competitors * fix: update * fix: update for Zotero * fix: Add complete example for loading API key with dummy .env path * fix: pylint missing docstrings * fix: line length issues (C0301) by breaking long lines into multiple lines * chore: update README and pyproject.toml --------- Co-authored-by: gurdeep330 <gurdeep330@gmail.com>
1 parent 1da9c0a commit 2fd0b40

31 files changed

+2037
-67
lines changed
 

‎.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -163,4 +163,7 @@ cython_debug/
163163
experiment/web/vectordb
164164

165165
# Streamlit
166-
.streamlit/secrets.toml
166+
.streamlit/secrets.toml
167+
168+
# macOS metadata file
169+
.DS_Store

‎README.md

+35-16
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
[![Talk2Cells](https://github.com/VirtualPatientEngine/AIAgents4Pharma/actions/workflows/tests_talk2cells.yml/badge.svg)](https://github.com/VirtualPatientEngine/AIAgents4Pharma/actions/workflows/tests_talk2cells.yml)
33
[![Talk2KnowledgeGraphs](https://github.com/VirtualPatientEngine/AIAgents4Pharma/actions/workflows/tests_talk2knowledgegraphs.yml/badge.svg)](https://github.com/VirtualPatientEngine/AIAgents4Pharma/actions/workflows/tests_talk2knowledgegraphs.yml)
44
[![Talk2Competitors](https://github.com/VirtualPatientEngine/AIAgents4Pharma/actions/workflows/tests_talk2competitors.yml/badge.svg)](https://github.com/VirtualPatientEngine/AIAgents4Pharma/actions/workflows/tests_talk2competitors.yml)
5+
![GitHub Release](https://img.shields.io/github/v/release/VirtualPatientEngine/AIAgents4Pharma)
6+
![Python Version from PEP 621 TOML](https://img.shields.io/python/required-version-toml?tomlFilePath=https%3A%2F%2Fraw.github.com%2FVirtualPatientEngine%2FAIAgents4Pharma%2Frefs%2Fheads%2Fmain%2Fpyproject.toml)
7+
58

69
<h1 align="center" style="border-bottom: none;">🤖 AIAgents4Pharma</h1>
710

@@ -10,9 +13,9 @@ Welcome to **AIAgents4Pharma** – an open-source project by [Team VPE](https://
1013
Our toolkit currently consists of three intelligent agents, each designed to simplify and enhance access to specialized data in biology:
1114

1215
- **Talk2BioModels**: Engage directly with mathematical models in systems biology.
13-
- **Talk2Cells** *(Work in progress)*: Query and analyze sequencing data with ease.
14-
- **Talk2KnowledgeGraphs** *(Work in progress)*: Access and explore complex biological knowledge graphs for insightful data connections.
15-
- **Talk2Competitors** *(Coming soon)*: Get recommendations for articles related to your choice. Download, query, and write/retrieve them to your reference manager (currently supporting Zotero).
16+
- **Talk2Cells** _(Work in progress)_: Query and analyze sequencing data with ease.
17+
- **Talk2KnowledgeGraphs** _(Work in progress)_: Access and explore complex biological knowledge graphs for insightful data connections.
18+
- **Talk2Competitors** _(Coming soon)_: Get recommendations for articles related to your choice. Download, query, and write/retrieve them to your reference manager (currently supporting Zotero).
1619

1720
---
1821

@@ -26,15 +29,15 @@ Our toolkit currently consists of three intelligent agents, each designed to sim
2629
- Adjust parameters within the model to simulate different conditions.
2730
- Query simulation results.
2831

29-
### 2. Talk2Cells *(Work in Progress)*
32+
### 2. Talk2Cells _(Work in Progress)_
3033

3134
**Talk2Cells** is being developed to provide direct access to and analysis of sequencing data, such as RNA-Seq or DNA-Seq, using natural language.
3235

33-
### 3. Talk2KnowledgeGraphs *(Work in Progress)*
36+
### 3. Talk2KnowledgeGraphs _(Work in Progress)_
3437

3538
**Talk2KnowledgeGraphs** is an agent designed to enable interaction with biological knowledge graphs (KGs). KGs integrate vast amounts of structured biological data into a format that highlights relationships between entities, such as proteins, genes, and diseases.
3639

37-
### 4. Talk2KnowledgeGraphs *(Coming soon)*
40+
### 4. Talk2Competitors _(Coming soon)_
3841

3942
## Getting Started
4043

@@ -45,48 +48,60 @@ Our toolkit currently consists of three intelligent agents, each designed to sim
4548
- Required libraries specified in `requirements.txt`
4649

4750
### Installation
51+
4852
#### Option 1: PyPI
49-
```bash
50-
pip install aiagents4pharma
51-
```
53+
54+
```bash
55+
pip install aiagents4pharma
56+
```
5257

5358
Check out the tutorials on each agent for detailed instrcutions.
5459

5560
#### Option 2: git
61+
5662
1. **Clone the repository:**
63+
5764
```bash
5865
git clone https://github.com/VirtualPatientEngine/AIAgents4Pharma
5966
cd AIAgents4Pharma
6067
```
6168

6269
2. **Install dependencies:**
70+
6371
```bash
6472
pip install .
6573
```
6674

6775
3. **Initialize OPENAI_API_KEY**
76+
6877
```bash
69-
export OPENAI_API_KEY = ....
78+
export OPENAI_API_KEY=....
7079
```
7180

7281
4. **[Optional] Set up login credentials**
82+
7383
```bash
7484
vi .streamlit/secrets.toml
7585
```
86+
7687
and enter
88+
7789
```
7890
password='XXX'
7991
```
80-
Please note that the passowrd will be same for all the users.
92+
93+
Please note that the passoword will be same for all the users.
8194

8295
5. **[Optional] Initialize LANGSMITH_API_KEY**
96+
8397
```bash
8498
export LANGCHAIN_TRACING_V2=true
8599
export LANGCHAIN_API_KEY=<your-api-key>
86100
```
87-
Please note that this will create a new tracing project in your Langsmith
88-
account with the name `<user_name>@<uuid>`, where `user_name` is the name
89-
you provided in the previous step. If you skip the previous step, it will
101+
102+
Please note that this will create a new tracing project in your Langsmith
103+
account with the name `<user_name>@<uuid>`, where `user_name` is the name
104+
you provided in the previous step. If you skip the previous step, it will
90105
default to `default`. <uuid> will be the 128 bit unique ID created for the
91106
session.
92107

@@ -118,6 +133,7 @@ We welcome contributions to AIAgents4Pharma! Here’s how you can help:
118133
5. **Open a pull request**
119134

120135
### Current Needs
136+
121137
- **Beta testers** for Talk2BioModels.
122138
- **Developers** with experience in natural language processing, bioinformatics, or knowledge graphs for contributions to AIAgents4Pharma.
123139

@@ -128,19 +144,22 @@ Check out our [CONTRIBUTING.md](CONTRIBUTING.md) for more information.
128144
## Roadmap
129145

130146
### Completed
147+
131148
- **Talk2BioModels**: Initial release with core capabilities for interacting with systems biology models.
132149

133150
### Planned
151+
134152
- **User Interface**: Interactive web UI for all agents.
135153
- **Talk2Cells**: Integration of sequencing data analysis tools.
136154
- **Talk2KnowledgeGraphs**: Interface for biological knowledge graph interaction.
137-
- **Talk2Competitors**
155+
- **Talk2Competitors**: Interface for exploring articles
138156

139-
We’re excited to bring AIAgents4Pharma to the bioinformatics and pharmaceutical research community. Together, let’s make data-driven biological research more accessible and insightful.
157+
We’re excited to bring AIAgents4Pharma to the bioinformatics and pharmaceutical research community. Together, let’s make data-driven biological research more accessible and insightful.
140158

141159
**Get Started** with AIAgents4Pharma today and transform the way you interact with biological data.
142160

143161
---
144162

145163
## Feedback
164+
146165
Questions/Bug reports/Feature requests/Comments/Suggestions? We welcome all. Please use the `Isssues` tab 😀

‎aiagents4pharma/__init__.py

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
'''
1+
"""
22
This file is used to import aiagents4pharma modules.
3-
'''
3+
"""
44

5-
from . import talk2biomodels
6-
from . import talk2cells
7-
from . import talk2knowledgegraphs
8-
from . import configs
5+
from . import (
6+
configs,
7+
talk2biomodels,
8+
talk2cells,
9+
talk2competitors,
10+
talk2knowledgegraphs,
11+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"""
2+
This file is used to import all the modules in the package.
3+
"""
4+
5+
from . import agents, config, state, tests, tools
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
'''
2+
This file is used to import all the modules in the package.
3+
'''
4+
5+
from . import main_agent
6+
from . import s2_agent
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
#!/usr/bin/env python3
2+
3+
"""
4+
Main agent for the talk2competitors app.
5+
"""
6+
7+
import logging
8+
from typing import Literal
9+
from dotenv import load_dotenv
10+
from langchain_core.language_models.chat_models import BaseChatModel
11+
from langchain_core.messages import AIMessage
12+
from langchain_openai import ChatOpenAI
13+
from langgraph.checkpoint.memory import MemorySaver
14+
from langgraph.graph import END, START, StateGraph
15+
from langgraph.types import Command
16+
from ..agents import s2_agent
17+
from ..config.config import config
18+
from ..state.state_talk2competitors import Talk2Competitors
19+
20+
logging.basicConfig(level=logging.INFO)
21+
logger = logging.getLogger(__name__)
22+
23+
load_dotenv()
24+
25+
def make_supervisor_node(llm: BaseChatModel) -> str:
26+
"""
27+
Creates a supervisor node following LangGraph patterns.
28+
29+
Args:
30+
llm (BaseChatModel): The language model to use for generating responses.
31+
32+
Returns:
33+
str: The supervisor node function.
34+
"""
35+
# options = ["FINISH", "s2_agent"]
36+
37+
def supervisor_node(state: Talk2Competitors) -> Command[Literal["s2_agent", "__end__"]]:
38+
"""
39+
Supervisor node that routes to appropriate sub-agents.
40+
41+
Args:
42+
state (Talk2Competitors): The current state of the conversation.
43+
44+
Returns:
45+
Command[Literal["s2_agent", "__end__"]]: The command to execute next.
46+
"""
47+
logger.info("Supervisor node called")
48+
49+
messages = [{"role": "system", "content": config.MAIN_AGENT_PROMPT}] + state[
50+
"messages"
51+
]
52+
response = llm.invoke(messages)
53+
goto = (
54+
"FINISH"
55+
if not any(
56+
kw in state["messages"][-1].content.lower()
57+
for kw in ["search", "paper", "find"]
58+
)
59+
else "s2_agent"
60+
)
61+
62+
if goto == "FINISH":
63+
return Command(
64+
goto=END,
65+
update={
66+
"messages": state["messages"]
67+
+ [AIMessage(content=response.content)],
68+
"is_last_step": True,
69+
"current_agent": None,
70+
},
71+
)
72+
73+
return Command(
74+
goto="s2_agent",
75+
update={
76+
"messages": state["messages"],
77+
"is_last_step": False,
78+
"current_agent": "s2_agent",
79+
},
80+
)
81+
82+
return supervisor_node
83+
84+
def get_app(thread_id: str, llm_model ='gpt-4o-mini') -> StateGraph:
85+
"""
86+
Returns the langraph app with hierarchical structure.
87+
88+
Args:
89+
thread_id (str): The thread ID for the conversation.
90+
91+
Returns:
92+
The compiled langraph app.
93+
"""
94+
def call_s2_agent(state: Talk2Competitors) -> Command[Literal["__end__"]]:
95+
"""
96+
Node for calling the S2 agent.
97+
98+
Args:
99+
state (Talk2Competitors): The current state of the conversation.
100+
101+
Returns:
102+
Command[Literal["__end__"]]: The command to execute next.
103+
"""
104+
logger.info("Calling S2 agent")
105+
app = s2_agent.get_app(thread_id, llm_model)
106+
response = app.invoke(state)
107+
logger.info("S2 agent completed")
108+
return Command(
109+
goto=END,
110+
update={
111+
"messages": response["messages"],
112+
"papers": response.get("papers", []),
113+
"is_last_step": True,
114+
"current_agent": "s2_agent",
115+
},
116+
)
117+
llm = ChatOpenAI(model=llm_model, temperature=0)
118+
workflow = StateGraph(Talk2Competitors)
119+
120+
supervisor = make_supervisor_node(llm)
121+
workflow.add_node("supervisor", supervisor)
122+
workflow.add_node("s2_agent", call_s2_agent)
123+
124+
# Define edges
125+
workflow.add_edge(START, "supervisor")
126+
workflow.add_edge("s2_agent", END)
127+
128+
app = workflow.compile(checkpointer=MemorySaver())
129+
logger.info("Main agent workflow compiled")
130+
return app
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#/usr/bin/env python3
2+
3+
'''
4+
Agent for interacting with Semantic Scholar
5+
'''
6+
7+
import logging
8+
from dotenv import load_dotenv
9+
from langchain_openai import ChatOpenAI
10+
from langgraph.graph import START, StateGraph
11+
from langgraph.prebuilt import create_react_agent
12+
from langgraph.checkpoint.memory import MemorySaver
13+
from ..config.config import config
14+
from ..state.state_talk2competitors import Talk2Competitors
15+
# from ..tools.s2 import s2_tools
16+
from ..tools.s2.search import search_tool
17+
from ..tools.s2.display_results import display_results
18+
from ..tools.s2.single_paper_rec import get_single_paper_recommendations
19+
from ..tools.s2.multi_paper_rec import get_multi_paper_recommendations
20+
21+
load_dotenv()
22+
23+
# Initialize logger
24+
logging.basicConfig(level=logging.INFO)
25+
logger = logging.getLogger(__name__)
26+
27+
def get_app(uniq_id, llm_model='gpt-4o-mini'):
28+
'''
29+
This function returns the langraph app.
30+
'''
31+
def agent_s2_node(state: Talk2Competitors):
32+
'''
33+
This function calls the model.
34+
'''
35+
logger.log(logging.INFO, "Creating Agent_S2 node with thread_id %s", uniq_id)
36+
response = model.invoke(state, {"configurable": {"thread_id": uniq_id}})
37+
return response
38+
39+
# Define the tools
40+
tools = [search_tool,
41+
display_results,
42+
get_single_paper_recommendations,
43+
get_multi_paper_recommendations]
44+
45+
# Create the LLM
46+
llm = ChatOpenAI(model=llm_model, temperature=0)
47+
model = create_react_agent(
48+
llm,
49+
tools=tools,
50+
state_schema=Talk2Competitors,
51+
state_modifier=config.S2_AGENT_PROMPT,
52+
checkpointer=MemorySaver()
53+
)
54+
55+
# Define a new graph
56+
workflow = StateGraph(Talk2Competitors)
57+
58+
# Define the two nodes we will cycle between
59+
workflow.add_node("agent_s2", agent_s2_node)
60+
61+
# Set the entrypoint as `agent`
62+
# This means that this node is the first one called
63+
workflow.add_edge(START, "agent_s2")
64+
65+
# Initialize memory to persist state between graph runs
66+
checkpointer = MemorySaver()
67+
68+
# Finally, we compile it!
69+
# This compiles it into a LangChain Runnable,
70+
# meaning you can use it as you would any other runnable.
71+
# Note that we're (optionally) passing the memory when compiling the graph
72+
app = workflow.compile(checkpointer=checkpointer)
73+
logger.log(logging.INFO, "Compiled the graph")
74+
75+
return app
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"""
2+
This package contains configuration settings and prompts used by various AI agents
3+
"""
4+
5+
from . import config

0 commit comments

Comments
 (0)
Please sign in to comment.