The error Could not convert 'part.function_call' to text has been fixed by adding proper error handling in backend/agents/base.py.
- Using
google-generativeaiSDK with manual function calling implementation - Custom
BaseAgentclass that handles tool execution - Works, but not using the official Google ADK framework
- Official Framework: Google ADK (
google-adk) is the official agent development kit - Better Abstractions: Built-in
Agentclass with automatic tool handling - Multi-Agent Support: Native support for agent orchestration
- Deployment Ready: Designed for Vertex AI Agent Engine deployment
pip install google-adk✅ Already installed
from google.generativeai import GenerativeModel
model = GenerativeModel(
model_name="gemini-2.0-flash-exp",
tools=[tool1, tool2]
)
# Manual function calling loop requiredfrom google.adk.agents.llm_agent import Agent
agent = Agent(
model='gemini-2.0-flash-exp',
name='my_agent',
description="Agent description",
instruction="System instruction",
tools=[tool1, tool2]
)
# Automatic function calling handled by ADKFile: backend/agents/base.py
from google.adk.agents.llm_agent import Agent as ADKAgent
from typing import List, Callable, Optional, Dict, Any
class BaseAgent:
def __init__(
self,
name: str,
model_name: str,
tools: Optional[List[Callable]] = None,
system_instruction: Optional[str] = None
):
self.name = name
self.agent = ADKAgent(
model=model_name,
name=name,
description=f"{name} agent",
instruction=system_instruction or "",
tools=tools or []
)
def query(self, input_text: str, session_id: str = None) -> Dict[str, Any]:
# ADK handles function calling automatically
response = self.agent.run(input_text)
return {
"answer": response.text,
"steps": []
}ADK tools should return simple types or dicts. Current tools already compatible:
def search_pubmed(query: str) -> str:
"""Searches PubMed for medical abstracts."""
results = fetch_pubmed_abstracts(query, max_results=5)
return json.dumps(results, indent=2)File: backend/agents/orchestrator.py
from google.adk.agents.llm_agent import Agent
from backend.agents.researcher import ResearcherAgent
from backend.agents.analyst import AnalystAgent
class OrchestratorAgent(BaseAgent):
def __init__(self):
self.researcher = ResearcherAgent()
self.analyst = AnalystAgent()
# Define delegation tools
def ask_researcher(question: str) -> str:
"""Delegates research questions to the Researcher Agent."""
result = self.researcher.query(question)
return result["answer"]
def ask_analyst(task: str) -> str:
"""Delegates analysis tasks to the Analyst Agent."""
result = self.analyst.query(task)
return result["answer"]
super().__init__(
name="Orchestrator",
model_name=Config.ORCHESTRATOR_MODEL,
tools=[ask_researcher, ask_analyst],
system_instruction="""
You are the Treg Research Assistant Orchestrator.
Delegate to specialized agents as needed.
"""
)-
Backup current working code:
git add -A git commit -m "Working version before ADK migration" -
Create a test branch:
git checkout -b feature/adk-migration
-
Implement changes incrementally:
- Start with BaseAgent
- Test with simple queries
- Update sub-agents
- Test orchestration
-
Validate:
python -m backend.api_server # Test with: "Find Phase 2 trials for Tregs"
- Cleaner Code: Less boilerplate for function calling
- Better Error Handling: ADK handles edge cases
- Deployment: Easy integration with Vertex AI Agent Engine
- Observability: Built-in logging and tracing
- Evaluation: ADK includes evaluation framework
The current implementation with google-generativeai + manual function calling works fine for development. The bug fix applied ensures stable operation.
Recommendation:
- ✅ Use current implementation for capstone submission (deadline: Dec 1, 11:59 AM PT)
- 🔄 Migrate to ADK post-submission for production deployment