-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Description
knowledge_retriever_agent = LlmAgent(
model=config.model,
name="knowledge_retriever_agent",
description="Retrieves rdocument. Executes a specific data retrieval tool exactly once.",
instruction="""
You are an autonomous system component that performs a single, non-negotiable task.
## STRICT INSTRUCTIONS:
1. **Execute Tool Once**: You must call the tool 'generate_test' exactly one time. Do not attempt to retry or re-call this tool for any reason, whether it times out, fails, or is slow.
3. **Call Tool**: Call 'generate_test' using that criteria.
4. **Wait/Complete**: Wait for the tool output to arrive (the system handles the execution). This tool may take some time to complete as it performs database operations.
5. **Final Response ONLY**: Once the tool returns, your final response *must only* be the exact string
""",
tools=[generate_test],
output_schema=KnowledgeRetrieverOutput,
output_key="knowledge_retriever_agent_output",
generate_content_config=GenerateContentConfig(
# Set temperature to 0.0 for maximum determinism and compliance to instructions.
temperature=0.0,
),
)
import logging
from typing import Dict, Any, List
Assuming these imports exist in your environment
from google.adk.tools import ToolContext
from app.utils.ToolTracker import tool_call_tracker
logger = logging.getLogger(name)
def generate_test(tool_context: ToolContext, acceptance_criteria: str) -> Dict[str, Any]:
"""
Simplified debug version of generate_test_scenarios.
This function mimics the interface and return structure of the original tool
but BYPASSES all MongoDB connections and sensitive Data Loading (PHI/PII).
It returns mock data to allow testing the agent flow safe from data privacy concerns.
"""
# 1. Get Context (Retain mostly same logic to debug context issues)
user_id = tool_context.state.get("current_user_id", "DEBUG_USER")
session_id = tool_context.state.get("current_session_id", "DEBUG_SESSION")
logger.info(f"[DEBUG TOOL] generate_test_scenarios called.")
logger.info(f"User: {user_id} | Session: {session_id}")
try:
# 2. BYPASS: Database Setup and PII Loading
# In the original code, this is where setup_vector_store() and
# auto_load_knowledge_base_one_chunk_per_file() would run.
logger.info("⚠️ SKIPPING MongoDB Setup and Data Loading to avoid PHI/PII usage.")
logger.info(f"Acceptance Criteria received: {acceptance_criteria[:100]}...")
# 3. logic Stub: Mock the Semantic Search results
# Instead of calling semantic_search_mongodb_..., we construct a safe response.
# Mock Knowledge Base Result
mock_kb_content = [
{
"content": (
"This is a MOCK knowledge base entry. "
"The actual vector search was skipped to protect PHI/PII data."
),
"metadata": {
"source_file": "debug_mock_file.txt",
"session_id": session_id,
"chunk_index": 1
},
"distance": 0.95
}
]
# Mock Application Flow
mock_app_flow = "Step 1: User Login (Mock)\nStep 2: Dashboard Navigation (Mock)"
logger.info(f"Generated {len(mock_kb_content)} mock KB items and mock App Flow.")
# 4. Return standard structure
return {
"knowledge_base_content": mock_kb_content,
"app_flow_content": mock_app_flow
}
except Exception as e:
logger.error(f"Error in debug scenario generation: {e}")
# Return empty structure on error, matching original behavior
return {
"knowledge_base_content": [],
"app_flow_content": ""
}
generate_test_tool = FunctionTool(func=generate_test)
I tried both FunctionTool as well as LongRunningTool call but since the tool call takes more than 10 sec agent is calling mulitple time ranging from 5 to 15 sec in a loop.
Using Google ADK : 1.2.0
Even afer adding the instruciton