IDAgents Developer commited on
Commit
c10e5be
Β·
1 Parent(s): 3562029

Fix: Don't reset chat when generating new agent - Allow agent creation during ongoing conversations

Browse files
Files changed (2) hide show
  1. PUBMED_SETUP.md +217 -0
  2. app.py +1 -4
PUBMED_SETUP.md ADDED
@@ -0,0 +1,217 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # πŸ”¬ PubMed Tool Configuration Guide
2
+
3
+ ## Environment Variable Required
4
+
5
+ To enable the PubMed search tool in your ID Agents app, you need to set the following environment variable:
6
+
7
+ ### **`NCBI_EMAIL`**
8
+
9
+ This is your email address that will be sent to NCBI (National Center for Biotechnology Information) with each API request.
10
+
11
+ ---
12
+
13
+ ## Why is Email Required?
14
+
15
+ NCBI requires an email address for E-utilities API access for the following reasons:
16
+
17
+ 1. **API Usage Monitoring**: NCBI uses email to track API usage patterns
18
+ 2. **Contact for Issues**: If there are problems with your requests, NCBI can contact you
19
+ 3. **Terms of Service**: It's part of NCBI's E-utilities usage guidelines
20
+ 4. **Rate Limiting**: Helps NCBI manage and enforce rate limits appropriately
21
+
22
+ ---
23
+
24
+ ## How to Set It Up
25
+
26
+ ### Option 1: HuggingFace Space (Recommended)
27
+
28
+ 1. Go to your HuggingFace Space: https://huggingface.co/spaces/John-jero/IDWeekAgents
29
+ 2. Click on **"Settings"** (gear icon)
30
+ 3. Navigate to **"Repository secrets"**
31
+ 4. Click **"Add a secret"**
32
+ 5. Enter:
33
+ - **Name**: `NCBI_EMAIL`
34
+ - **Value**: Your email address (e.g., `[email protected]`)
35
+ 6. Click **"Save"**
36
+ 7. **Restart your space** for changes to take effect
37
+
38
+ ### Option 2: Local Development (.env file)
39
+
40
+ If running locally, create/edit your `.env` file:
41
+
42
+ ```bash
43
+ # .env file
44
+ OPENAI_API_KEY=your-openai-api-key-here
45
46
+ ```
47
+
48
+ ---
49
+
50
+ ## What Email Should I Use?
51
+
52
+ ### βœ… Recommended:
53
+ - **Institutional email**: `[email protected]`
54
+ - **Work email**: `[email protected]`
55
+ - **Academic email**: `[email protected]`
56
+
57
+ ### ⚠️ Acceptable:
58
+ - Personal email (Gmail, Yahoo, etc.)
59
+ - Any valid email address
60
+
61
+ ### ❌ Not Recommended:
62
+ - Fake or invalid emails
63
+ - Generic emails like `[email protected]`
64
+ - Temporary/disposable emails
65
+
66
+ **Best Practice**: Use a real, professional email address associated with your institution or work.
67
+
68
+ ---
69
+
70
+ ## Optional: NCBI API Key
71
+
72
+ For **higher rate limits**, you can also register for a free NCBI API key:
73
+
74
+ ### How to Get an NCBI API Key:
75
+
76
+ 1. Go to: https://www.ncbi.nlm.nih.gov/account/
77
+ 2. **Sign in** or **Register** for an NCBI account
78
+ 3. Go to **Settings** β†’ **API Key Management**
79
+ 4. Click **"Create an API Key"**
80
+ 5. Copy your API key
81
+
82
+ ### Add to HuggingFace Space:
83
+
84
+ - **Name**: `NCBI_API_KEY`
85
+ - **Value**: Your NCBI API key
86
+
87
+ ### Benefits:
88
+ - **Without API Key**: 3 requests/second
89
+ - **With API Key**: 10 requests/second
90
+
91
+ ---
92
+
93
+ ## Default Behavior
94
+
95
+ If you **don't set** `NCBI_EMAIL`, the tool will use a default:
96
+
97
+ ```python
98
+ # From tools/pubmed_search.py line 67:
99
+ if not email:
100
+ email = "[email protected]"
101
+ logger.info("Using default email for NCBI API access")
102
+ ```
103
+
104
+ This will work, but it's **better to set your own email** for:
105
+ - βœ… Proper attribution
106
+ - βœ… NCBI can contact you if needed
107
+ - βœ… Better compliance with NCBI guidelines
108
+
109
+ ---
110
+
111
+ ## How to Verify It's Working
112
+
113
+ ### Test in Your Agent:
114
+
115
+ 1. **Create an agent** with the **"search_pubmed"** skill
116
+ 2. **Chat with the agent** and ask:
117
+ ```
118
+ "Search PubMed for recent articles on C. difficile treatment"
119
+ ```
120
+ 3. **Check the response**:
121
+ - βœ… Should return recent articles with titles, authors, PMIDs
122
+ - ❌ If error, check your email is set correctly
123
+
124
+ ### Check Logs:
125
+
126
+ In your HuggingFace Space logs, you should see:
127
+ ```
128
+ INFO: Using email: [email protected] for NCBI API access
129
+ ```
130
+
131
+ ---
132
+
133
+ ## Complete Environment Variables Setup
134
+
135
+ For full functionality, set these in HuggingFace Space Settings β†’ Repository secrets:
136
+
137
+ ### **Required**:
138
+ ```
139
+ OPENAI_API_KEY=sk-...your-openai-key
140
+ AUTH_CREDENTIALS=username:password,user2:pass2
141
+ ```
142
+
143
+ ### **Optional (but recommended)**:
144
+ ```
145
146
+ NCBI_API_KEY=your-ncbi-api-key
147
+ SERPER_API_KEY=your-serper-key
148
+ ```
149
+
150
+ ---
151
+
152
+ ## Troubleshooting
153
+
154
+ ### Problem: PubMed search returns no results or errors
155
+
156
+ **Solution 1**: Check email is set
157
+ ```bash
158
+ # In Space Settings β†’ Secrets, verify:
159
+ NCBI_EMAIL = [email protected]
160
+ ```
161
+
162
+ **Solution 2**: Restart your space after adding the secret
163
+
164
+ **Solution 3**: Check logs for specific error messages
165
+
166
+ ### Problem: Rate limit errors
167
+
168
+ **Solution**: Add `NCBI_API_KEY` to increase rate limit from 3 to 10 requests/second
169
+
170
+ ### Problem: "Invalid email" errors
171
+
172
+ **Solution**: Use a properly formatted email address: `[email protected]`
173
+
174
+ ---
175
+
176
+ ## Code Reference
177
+
178
+ The PubMed tool code is in: `tools/pubmed_search.py`
179
+
180
+ Key lines:
181
+ ```python
182
+ # Line 37: Email parameter with environment variable default
183
+ "email": {"type": "string", "description": "user email for NCBI API",
184
+ "default": os.getenv("NCBI_EMAIL", "")}
185
+
186
+ # Line 62-67: Email fallback logic
187
+ if not email:
188
+ email = os.getenv("NCBI_EMAIL", "")
189
+
190
+ if not email:
191
+ email = "[email protected]"
192
+ logger.info("Using default email for NCBI API access")
193
+ ```
194
+
195
+ ---
196
+
197
+ ## Quick Setup Checklist
198
+
199
+ - [ ] Go to HuggingFace Space Settings
200
+ - [ ] Navigate to Repository secrets
201
+ - [ ] Add secret: `NCBI_EMAIL` = your email
202
+ - [ ] (Optional) Add secret: `NCBI_API_KEY` = your API key
203
+ - [ ] Restart your space
204
+ - [ ] Test PubMed search with an agent
205
+ - [ ] Verify results are returned
206
+
207
+ ---
208
+
209
+ ## Summary
210
+
211
+ **Environment Variable**: `NCBI_EMAIL`
212
+ **Value**: Your email address
213
+ **Location**: HuggingFace Space Settings β†’ Repository secrets
214
+ **Required**: Technically optional, but strongly recommended
215
+ **Format**: `[email protected]`
216
+
217
+ **After setting it, restart your space and the PubMed tool will work with your email!** πŸ“§πŸ”¬
app.py CHANGED
@@ -2158,10 +2158,7 @@ def build_ui():
2158
  web_access_toggle, allow_fallback_toggle,
2159
  uploaded_files, link1, link2, link3, link4, challenger_toggle],
2160
  outputs=[agent_output] # <- only the JSON
2161
- ).then( # 2) show initial instruction instead of preload demo chat
2162
- lambda: show_initial_instruction_state(),
2163
- inputs=[], outputs=[builder_chatbot, chat_input, builder_send_button, reset_button, invocation_log, active_children]
2164
- ).then( # 2.5) auto-load agent fields into builder panel
2165
  lambda agent_json: (
2166
  json.loads(agent_json).get("agent_type", ""),
2167
  json.loads(agent_json).get("agent_name", ""),
 
2158
  web_access_toggle, allow_fallback_toggle,
2159
  uploaded_files, link1, link2, link3, link4, challenger_toggle],
2160
  outputs=[agent_output] # <- only the JSON
2161
+ ).then( # 2) auto-load agent fields into builder panel
 
 
 
2162
  lambda agent_json: (
2163
  json.loads(agent_json).get("agent_type", ""),
2164
  json.loads(agent_json).get("agent_name", ""),