Skip to content

medical agent fix#482

Merged
raahulrahl merged 2 commits into
GetBindu:mainfrom
Paraschamoli:feat/examples-fix
Apr 20, 2026
Merged

medical agent fix#482
raahulrahl merged 2 commits into
GetBindu:mainfrom
Paraschamoli:feat/examples-fix

Conversation

@Paraschamoli
Copy link
Copy Markdown
Member

@Paraschamoli Paraschamoli commented Apr 20, 2026

Summary by CodeRabbit

Release Notes

  • New Features

    • Added Medical Research Agent example with web search integration for medical research and health information retrieval, including symptom analysis, drug information, and wellness guidance.
  • Documentation

    • Added comprehensive setup guide with configuration instructions, usage examples, API endpoints documentation, and troubleshooting guidance for the Medical Research Agent.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 20, 2026

📝 Walkthrough

Walkthrough

The PR reorganizes the medical agent example by restructuring the implementation from agent.py to medical_agent.py, adding comprehensive README documentation, introducing a skill definition file, and updating the environment variable placeholder format for OpenRouter API keys.

Changes

Cohort / File(s) Summary
Environment & Documentation
examples/medical_agent/.env.example, examples/medical_agent/README.md
Updated API key placeholder format and added extensive documentation covering agent features, setup instructions, API endpoints, configuration, troubleshooting, and medical disclaimer information.
Agent Implementation Restructure
examples/medical_agent/agent.py, examples/medical_agent/medical_agent.py
Removed original agent.py and introduced restructured medical_agent.py with refactored handler() function that includes fallback logic for result extraction and user prompts when no messages are provided.
Skill Definition
examples/medical_agent/skills/medical-research-skill/skill.yaml
Added skill configuration file defining medical research capabilities, including symptom analysis, drug information, wellness guidance, and DuckDuckGo search integration with JSON input/output modes.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Poem

🐰 A medical agent hops into view,
With skills and docs, both shiny and new!
From agent.py's burrow to medical_agent's care,
OpenRouter and DuckDuckGo search everywhere! 🔍
Health wisdom flows, disclaimers too—
What fine refactoring we do! 🌿

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Description check ⚠️ Warning No pull request description was provided; the description template requires multiple sections including summary, change type, scope, and verification details that are completely missing. Add a comprehensive pull request description following the repository template, including problem statement, change summary, change type, scope, verification steps, security impact assessment, and human verification details.
Title check ❓ Inconclusive The title 'medical agent fix' is vague and non-descriptive, lacking specificity about what was fixed or changed in the medical agent. Provide a more descriptive title that explains the specific change, such as 'Refactor medical agent to use medical_agent.py entrypoint' or 'Update medical agent configuration and documentation'.
✅ Passed checks (1 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🧹 Nitpick comments (2)
examples/medical_agent/medical_agent.py (2)

20-29: Move load_dotenv() call after imports, or keep imports at top of file (PEP 8).

Per PEP 8, all imports should appear at the top of the module. load_dotenv() only needs to run before os.getenv("OPENROUTER_API_KEY") is evaluated (line 52), not before the agno/bindu imports. Reordering will also likely resolve the pre-commit trailing-whitespace / formatting pipeline failure cleanly.

♻️ Proposed reordering
 import os
 from dotenv import load_dotenv
-
-# Load environment variables from .env file
-load_dotenv()
 
 from bindu.penguin.bindufy import bindufy
 from agno.agent import Agent
 from agno.tools.duckduckgo import DuckDuckGoTools
 from agno.models.openrouter import OpenRouter
+
+# Load environment variables from .env file
+load_dotenv()
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@examples/medical_agent/medical_agent.py` around lines 20 - 29, The call to
load_dotenv() is currently before module imports, violating PEP 8; move the
load_dotenv() invocation so all imports (e.g., from bindu.penguin.bindufy import
bindufy, from agno.agent import Agent, from agno.tools.duckduckgo import
DuckDuckGoTools, from agno.models.openrouter import OpenRouter) remain at the
top of the file, then call load_dotenv() afterwards but before any use of
environment variables (specifically before os.getenv("OPENROUTER_API_KEY") /
OpenRouter instantiation) so env vars are available when needed.

72-97: Handler edge cases and response extraction.

A few small robustness points:

  • Line 84: messages[-1].get('content', '') may yield an empty string, which is then passed to agent.run(input=""). Consider falling back to the prompt message (line 97) when content is empty/whitespace, instead of only when messages is empty.
  • Lines 90–95: checking hasattr(result, 'content') and then 'response' is a fragile duck-typing ladder. If the Agno RunResponse API is known, access .content directly (or via result.to_dict()["content"] as shown in the bindufy docstring example) rather than falling through to str(result), which can leak internal repr.
  • Add a return type annotation (-> str) for clarity and to match the docstring contract.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@examples/medical_agent/medical_agent.py` around lines 72 - 97, The handler
function should declare a return type (-> str), treat empty/whitespace latest
message as missing by falling back to the default prompt, and extract the agent
output in a robust way instead of fragile hasattr checks; update handler to
compute latest_message by trimming messages[-1].get('content','') and if that is
empty use the fallback prompt, call agent.run(input=latest_message), then
extract the response from the known RunResponse shape (access .content directly
or use result.to_dict()["content"] if a dict form is provided) and return that
string; avoid using hasattr checks and str(result) to prevent leaking internal
repr.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@examples/medical_agent/medical_agent.py`:
- Around line 34-49: Remove trailing whitespace characters from the multi-line
string assigned to the variable instructions in medical_agent.py (the line
ending after "disclaimers." and any other lines in that string); run the
pre-commit hooks locally (pre-commit run --all-files) to verify and let the
hooks auto-fix remaining trailing-whitespace issues, then stage and commit the
updated file so CI no longer fails.
- Around line 50-53: Before constructing the OpenRouter model, explicitly check
that os.getenv("OPENROUTER_API_KEY") returns a non-empty value and raise a clear
error if it's missing; replace the inline call in the OpenRouter(...)
instantiation (the model=OpenRouter(...) block) with a validated variable (e.g.,
openrouter_api_key) and if it's None or empty raise a RuntimeError or ValueError
with a message instructing the user to set OPENROUTER_API_KEY (and reference the
README/.env), so the application fails fast with a helpful message instead of
surfacing a cryptic downstream client error.

In `@examples/medical_agent/README.md`:
- Around line 123-128: Update the troubleshooting snippet to use the same API
key placeholder as .env.example: replace the `OPENROUTER_API_KEY=your_key_here`
instruction with `OPENROUTER_API_KEY=sk-or-v1-<your-api-key>` (or alternatively
change .env.example to use `your_key_here` if you prefer that style); ensure the
README and .env.example use the identical placeholder string so references to
OPENROUTER_API_KEY are consistent across docs.
- Around line 68-73: Add missing fenced-code block language identifiers for the
two Markdown code blocks; update the block containing the "Flu Symptoms
Overview" example to use a language tag like ```markdown (or ```text) and update
the directory-tree/code block later (the one around lines 98–110) to use ```text
so markdownlint MD040 is satisfied—locate the fenced blocks that wrap the "Flu
Symptoms Overview" paragraph and the directory tree and prepend the appropriate
language specifier after the opening backticks.

In `@examples/medical_agent/skills/medical-research-skill/skill.yaml`:
- Around line 28-38: The declared input/output MIME types in skill.yaml
(input_modes/output_modes) don't match actual usage; update input_modes to
"text/plain" (since the handler in medical_agent.py extracts request.content as
a string) and update output_modes to "text/markdown" (or "text/plain" if you
prefer plain text) so the skill I/O contract reflects the handler's
string/markdown responses; also verify the handler code that extracts content
and returns the response (in medical_agent.py) aligns with the chosen output
MIME type.

---

Nitpick comments:
In `@examples/medical_agent/medical_agent.py`:
- Around line 20-29: The call to load_dotenv() is currently before module
imports, violating PEP 8; move the load_dotenv() invocation so all imports
(e.g., from bindu.penguin.bindufy import bindufy, from agno.agent import Agent,
from agno.tools.duckduckgo import DuckDuckGoTools, from agno.models.openrouter
import OpenRouter) remain at the top of the file, then call load_dotenv()
afterwards but before any use of environment variables (specifically before
os.getenv("OPENROUTER_API_KEY") / OpenRouter instantiation) so env vars are
available when needed.
- Around line 72-97: The handler function should declare a return type (-> str),
treat empty/whitespace latest message as missing by falling back to the default
prompt, and extract the agent output in a robust way instead of fragile hasattr
checks; update handler to compute latest_message by trimming
messages[-1].get('content','') and if that is empty use the fallback prompt,
call agent.run(input=latest_message), then extract the response from the known
RunResponse shape (access .content directly or use result.to_dict()["content"]
if a dict form is provided) and return that string; avoid using hasattr checks
and str(result) to prevent leaking internal repr.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 116fd29a-703f-44fe-bf12-06cb934f95dc

📥 Commits

Reviewing files that changed from the base of the PR and between 3ccdc60 and 2b8e28a.

📒 Files selected for processing (6)
  • examples/ai-data-analysis-agent/skills/ai-data-analysis-agent/skill.yaml
  • examples/medical_agent/.env.example
  • examples/medical_agent/README.md
  • examples/medical_agent/agent.py
  • examples/medical_agent/medical_agent.py
  • examples/medical_agent/skills/medical-research-skill/skill.yaml
💤 Files with no reviewable changes (1)
  • examples/medical_agent/agent.py

Comment on lines +34 to +49
instructions="""You are a medical research assistant. When asked about health or medical topics, provide clear, accurate information with appropriate disclaimers.

Key guidelines:
- Always include a medical disclaimer stating this is not professional medical advice
- Provide general health information and educational content
- For specific medical concerns, recommend consulting healthcare professionals
- Use web search to find current, reliable medical information
- Present information in an organized, easy-to-read format
- Avoid making definitive diagnoses or treatment recommendations
- Focus on evidence-based information from reputable sources

Response format:
- Start with relevant medical information
- Include supporting details and context
- End with a clear medical disclaimer
- Avoid showing multiple search results - synthesize information coherently""",
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Pre-commit trailing-whitespace failure.

CI reports trailing-whitespace hook modified this file. Line 34 ends with a trailing space after disclaimers. (and possibly others). Please run pre-commit run --all-files locally and commit the fixes so CI passes.

🧰 Tools
🪛 GitHub Actions: CI

[error] pre-commit trailing-whitespace hook failed (exit code 1): files were modified by this hook (Fixing examples/medical_agent/medical_agent.py).

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@examples/medical_agent/medical_agent.py` around lines 34 - 49, Remove
trailing whitespace characters from the multi-line string assigned to the
variable instructions in medical_agent.py (the line ending after "disclaimers."
and any other lines in that string); run the pre-commit hooks locally
(pre-commit run --all-files) to verify and let the hooks auto-fix remaining
trailing-whitespace issues, then stage and commit the updated file so CI no
longer fails.

Comment on lines +50 to +53
model=OpenRouter(
id="google/gemini-2.0-flash-001",
api_key=os.getenv("OPENROUTER_API_KEY")
),
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Validate OPENROUTER_API_KEY is set before constructing the model.

os.getenv("OPENROUTER_API_KEY") silently returns None if the variable is missing, which will surface as a confusing downstream error from the OpenRouter client at request time rather than at startup. Fail fast with a clear message so users know to populate .env (the README's troubleshooting section already references this exact error).

🛡️ Proposed fix
+api_key = os.getenv("OPENROUTER_API_KEY")
+if not api_key:
+    raise RuntimeError(
+        "OPENROUTER_API_KEY is not set. Copy .env.example to .env and set your key."
+    )
+
 agent = Agent(
     ...
     model=OpenRouter(
         id="google/gemini-2.0-flash-001",
-        api_key=os.getenv("OPENROUTER_API_KEY")
+        api_key=api_key,
     ),
🧰 Tools
🪛 GitHub Actions: CI

[error] pre-commit trailing-whitespace hook failed (exit code 1): files were modified by this hook (Fixing examples/medical_agent/medical_agent.py).

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@examples/medical_agent/medical_agent.py` around lines 50 - 53, Before
constructing the OpenRouter model, explicitly check that
os.getenv("OPENROUTER_API_KEY") returns a non-empty value and raise a clear
error if it's missing; replace the inline call in the OpenRouter(...)
instantiation (the model=OpenRouter(...) block) with a validated variable (e.g.,
openrouter_api_key) and if it's None or empty raise a RuntimeError or ValueError
with a message instructing the user to set OPENROUTER_API_KEY (and reference the
README/.env), so the application fails fast with a helpful message instead of
surfacing a cryptic downstream client error.

Comment on lines +68 to +73
```
**Flu Symptoms Overview**
- Common symptoms: Fever, cough, sore throat, body aches
- Less common: Headache, fatigue, vomiting, diarrhea
- **Important**: This information is for educational purposes only. Always consult a healthcare professional for medical advice, diagnosis, or treatment.
```
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Add language identifiers to fenced code blocks (MD040).

markdownlint flags lines 68 and 98 for missing language specifiers. Use ```text (or ```markdown for the response example at 68, and ```text for the directory tree at 98).

As per static analysis hints: MD040, fenced-code-language.

Also applies to: 98-110

🧰 Tools
🪛 markdownlint-cli2 (0.22.0)

[warning] 68-68: Fenced code blocks should have a language specified

(MD040, fenced-code-language)

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@examples/medical_agent/README.md` around lines 68 - 73, Add missing
fenced-code block language identifiers for the two Markdown code blocks; update
the block containing the "Flu Symptoms Overview" example to use a language tag
like ```markdown (or ```text) and update the directory-tree/code block later
(the one around lines 98–110) to use ```text so markdownlint MD040 is
satisfied—locate the fenced blocks that wrap the "Flu Symptoms Overview"
paragraph and the directory tree and prepend the appropriate language specifier
after the opening backticks.

Comment on lines +123 to +128
#### API Key Not Found
**Error**: `OPENROUTER_API_KEY not set`
**Solution**:
1. Copy your OpenRouter API key
2. Add to `.env` file: `OPENROUTER_API_KEY=your_key_here`
3. Restart the agent
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Troubleshooting snippet is inconsistent with .env.example.

.env.example now uses the placeholder sk-or-v1-<your-api-key>, but this section instructs users to set OPENROUTER_API_KEY=your_key_here. Align the two so users see one consistent format.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@examples/medical_agent/README.md` around lines 123 - 128, Update the
troubleshooting snippet to use the same API key placeholder as .env.example:
replace the `OPENROUTER_API_KEY=your_key_here` instruction with
`OPENROUTER_API_KEY=sk-or-v1-<your-api-key>` (or alternatively change
.env.example to use `your_key_here` if you prefer that style); ensure the README
and .env.example use the identical placeholder string so references to
OPENROUTER_API_KEY are consistent across docs.

Comment on lines +28 to +38
input_modes:
- application/json
output_modes:
- application/json
examples:
- "What are the symptoms of flu?"
- "Provide information about ibuprofen side effects"
- "How to prevent common cold?"
- "What are the benefits of regular exercise?"
- "Explain the symptoms of diabetes"
- "Give tips for better sleep hygiene"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Input/output modes may not match actual usage.

input_modes/output_modes are declared as application/json, but the example prompts are plain-text strings and the handler in medical_agent.py extracts content as a string and returns a string/markdown response. Consider using text/plain (or text/markdown for output) to accurately describe the skill's I/O contract.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@examples/medical_agent/skills/medical-research-skill/skill.yaml` around lines
28 - 38, The declared input/output MIME types in skill.yaml
(input_modes/output_modes) don't match actual usage; update input_modes to
"text/plain" (since the handler in medical_agent.py extracts request.content as
a string) and update output_modes to "text/markdown" (or "text/plain" if you
prefer plain text) so the skill I/O contract reflects the handler's
string/markdown responses; also verify the handler code that extracts content
and returns the response (in medical_agent.py) aligns with the chosen output
MIME type.

@raahulrahl raahulrahl merged commit e545786 into GetBindu:main Apr 20, 2026
3 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants