agent-starter-pack 0.11.0__py3-none-any.whl → 0.11.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {agent_starter_pack-0.11.0.dist-info → agent_starter_pack-0.11.2.dist-info}/METADATA +9 -2
- {agent_starter_pack-0.11.0.dist-info → agent_starter_pack-0.11.2.dist-info}/RECORD +11 -18
- src/base_template/deployment/terraform/dev/variables.tf +3 -2
- src/base_template/deployment/terraform/iam.tf +10 -34
- src/base_template/deployment/terraform/variables.tf +3 -3
- src/base_template/{% if cookiecutter.cicd_runner == 'github_actions' %}.github{% else %}unused_github{% endif %}/workflows/deploy-to-prod.yaml +2 -0
- src/cli/commands/enhance.py +70 -16
- src/cli/commands/setup_cicd.py +50 -41
- agents/adk_gemini_fullstack/.template/templateconfig.yaml +0 -39
- agents/adk_gemini_fullstack/README.md +0 -27
- agents/adk_gemini_fullstack/app/agent.py +0 -412
- agents/adk_gemini_fullstack/app/config.py +0 -46
- agents/adk_gemini_fullstack/notebooks/adk_app_testing.ipynb +0 -355
- agents/adk_gemini_fullstack/notebooks/evaluating_adk_agent.ipynb +0 -1528
- agents/adk_gemini_fullstack/tests/integration/test_agent.py +0 -58
- {agent_starter_pack-0.11.0.dist-info → agent_starter_pack-0.11.2.dist-info}/WHEEL +0 -0
- {agent_starter_pack-0.11.0.dist-info → agent_starter_pack-0.11.2.dist-info}/entry_points.txt +0 -0
- {agent_starter_pack-0.11.0.dist-info → agent_starter_pack-0.11.2.dist-info}/licenses/LICENSE +0 -0
@@ -1,412 +0,0 @@
|
|
1
|
-
# Copyright 2025 Google LLC
|
2
|
-
#
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
-
# you may not use this file except in compliance with the License.
|
5
|
-
# You may obtain a copy of the License at
|
6
|
-
#
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
-
#
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
-
# See the License for the specific language governing permissions and
|
13
|
-
# limitations under the License.
|
14
|
-
|
15
|
-
import datetime
|
16
|
-
import logging
|
17
|
-
import re
|
18
|
-
from collections.abc import AsyncGenerator
|
19
|
-
from typing import Literal
|
20
|
-
|
21
|
-
from google.adk.agents import BaseAgent, LlmAgent, LoopAgent, SequentialAgent
|
22
|
-
from google.adk.agents.callback_context import CallbackContext
|
23
|
-
from google.adk.agents.invocation_context import InvocationContext
|
24
|
-
from google.adk.events import Event, EventActions
|
25
|
-
from google.adk.planners import BuiltInPlanner
|
26
|
-
from google.adk.tools import google_search
|
27
|
-
from google.adk.tools.agent_tool import AgentTool
|
28
|
-
from google.genai import types as genai_types
|
29
|
-
from pydantic import BaseModel, Field
|
30
|
-
|
31
|
-
from .config import config
|
32
|
-
|
33
|
-
|
34
|
-
# --- Structured Output Models ---
|
35
|
-
class SearchQuery(BaseModel):
|
36
|
-
"""Model representing a specific search query for web search."""
|
37
|
-
|
38
|
-
search_query: str = Field(
|
39
|
-
description="A highly specific and targeted query for web search."
|
40
|
-
)
|
41
|
-
|
42
|
-
|
43
|
-
class Feedback(BaseModel):
|
44
|
-
"""Model for providing evaluation feedback on research quality."""
|
45
|
-
|
46
|
-
grade: Literal["pass", "fail"] = Field(
|
47
|
-
description="Evaluation result. 'pass' if the research is sufficient, 'fail' if it needs revision."
|
48
|
-
)
|
49
|
-
comment: str = Field(
|
50
|
-
description="Detailed explanation of the evaluation, highlighting strengths and/or weaknesses of the research."
|
51
|
-
)
|
52
|
-
follow_up_queries: list[SearchQuery] | None = Field(
|
53
|
-
default=None,
|
54
|
-
description="A list of specific, targeted follow-up search queries needed to fix research gaps. This should be null or empty if the grade is 'pass'.",
|
55
|
-
)
|
56
|
-
|
57
|
-
|
58
|
-
# --- Callbacks ---
|
59
|
-
def collect_research_sources_callback(callback_context: CallbackContext) -> None:
|
60
|
-
"""Collects and organizes web-based research sources and their supported claims from agent events.
|
61
|
-
|
62
|
-
This function processes the agent's `session.events` to extract web source details (URLs,
|
63
|
-
titles, domains from `grounding_chunks`) and associated text segments with confidence scores
|
64
|
-
(from `grounding_supports`). The aggregated source information and a mapping of URLs to short
|
65
|
-
IDs are cumulatively stored in `callback_context.state`.
|
66
|
-
|
67
|
-
Args:
|
68
|
-
callback_context (CallbackContext): The context object providing access to the agent's
|
69
|
-
session events and persistent state.
|
70
|
-
"""
|
71
|
-
session = callback_context._invocation_context.session
|
72
|
-
url_to_short_id = callback_context.state.get("url_to_short_id", {})
|
73
|
-
sources = callback_context.state.get("sources", {})
|
74
|
-
id_counter = len(url_to_short_id) + 1
|
75
|
-
for event in session.events:
|
76
|
-
if not (event.grounding_metadata and event.grounding_metadata.grounding_chunks):
|
77
|
-
continue
|
78
|
-
chunks_info = {}
|
79
|
-
for idx, chunk in enumerate(event.grounding_metadata.grounding_chunks):
|
80
|
-
if not chunk.web:
|
81
|
-
continue
|
82
|
-
url = chunk.web.uri
|
83
|
-
title = (
|
84
|
-
chunk.web.title
|
85
|
-
if chunk.web.title != chunk.web.domain
|
86
|
-
else chunk.web.domain
|
87
|
-
)
|
88
|
-
if url not in url_to_short_id:
|
89
|
-
short_id = f"src-{id_counter}"
|
90
|
-
url_to_short_id[url] = short_id
|
91
|
-
sources[short_id] = {
|
92
|
-
"short_id": short_id,
|
93
|
-
"title": title,
|
94
|
-
"url": url,
|
95
|
-
"domain": chunk.web.domain,
|
96
|
-
"supported_claims": [],
|
97
|
-
}
|
98
|
-
id_counter += 1
|
99
|
-
chunks_info[idx] = url_to_short_id[url]
|
100
|
-
if event.grounding_metadata.grounding_supports:
|
101
|
-
for support in event.grounding_metadata.grounding_supports:
|
102
|
-
confidence_scores = support.confidence_scores or []
|
103
|
-
chunk_indices = support.grounding_chunk_indices or []
|
104
|
-
for i, chunk_idx in enumerate(chunk_indices):
|
105
|
-
if chunk_idx in chunks_info:
|
106
|
-
short_id = chunks_info[chunk_idx]
|
107
|
-
confidence = (
|
108
|
-
confidence_scores[i] if i < len(confidence_scores) else 0.5
|
109
|
-
)
|
110
|
-
text_segment = support.segment.text if support.segment else ""
|
111
|
-
sources[short_id]["supported_claims"].append(
|
112
|
-
{
|
113
|
-
"text_segment": text_segment,
|
114
|
-
"confidence": confidence,
|
115
|
-
}
|
116
|
-
)
|
117
|
-
callback_context.state["url_to_short_id"] = url_to_short_id
|
118
|
-
callback_context.state["sources"] = sources
|
119
|
-
|
120
|
-
|
121
|
-
def citation_replacement_callback(
|
122
|
-
callback_context: CallbackContext,
|
123
|
-
) -> genai_types.Content:
|
124
|
-
"""Replaces citation tags in a report with Markdown-formatted links.
|
125
|
-
|
126
|
-
Processes 'final_cited_report' from context state, converting tags like
|
127
|
-
`<cite source="src-N"/>` into hyperlinks using source information from
|
128
|
-
`callback_context.state["sources"]`. Also fixes spacing around punctuation.
|
129
|
-
|
130
|
-
Args:
|
131
|
-
callback_context (CallbackContext): Contains the report and source information.
|
132
|
-
|
133
|
-
Returns:
|
134
|
-
genai_types.Content: The processed report with Markdown citation links.
|
135
|
-
"""
|
136
|
-
final_report = callback_context.state.get("final_cited_report", "")
|
137
|
-
sources = callback_context.state.get("sources", {})
|
138
|
-
|
139
|
-
def tag_replacer(match: re.Match) -> str:
|
140
|
-
short_id = match.group(1)
|
141
|
-
if not (source_info := sources.get(short_id)):
|
142
|
-
logging.warning(f"Invalid citation tag found and removed: {match.group(0)}")
|
143
|
-
return ""
|
144
|
-
display_text = source_info.get("title", source_info.get("domain", short_id))
|
145
|
-
return f" [{display_text}]({source_info['url']})"
|
146
|
-
|
147
|
-
processed_report = re.sub(
|
148
|
-
r'<cite\s+source\s*=\s*["\']?\s*(src-\d+)\s*["\']?\s*/>',
|
149
|
-
tag_replacer,
|
150
|
-
final_report,
|
151
|
-
)
|
152
|
-
processed_report = re.sub(r"\s+([.,;:])", r"\1", processed_report)
|
153
|
-
callback_context.state["final_report_with_citations"] = processed_report
|
154
|
-
return genai_types.Content(parts=[genai_types.Part(text=processed_report)])
|
155
|
-
|
156
|
-
|
157
|
-
# --- Custom Agent for Loop Control ---
|
158
|
-
class EscalationChecker(BaseAgent):
|
159
|
-
"""Checks research evaluation and escalates to stop the loop if grade is 'pass'."""
|
160
|
-
|
161
|
-
def __init__(self, name: str):
|
162
|
-
super().__init__(name=name)
|
163
|
-
|
164
|
-
async def _run_async_impl(
|
165
|
-
self, ctx: InvocationContext
|
166
|
-
) -> AsyncGenerator[Event, None]:
|
167
|
-
evaluation_result = ctx.session.state.get("research_evaluation")
|
168
|
-
if evaluation_result and evaluation_result.get("grade") == "pass":
|
169
|
-
logging.info(
|
170
|
-
f"[{self.name}] Research evaluation passed. Escalating to stop loop."
|
171
|
-
)
|
172
|
-
yield Event(author=self.name, actions=EventActions(escalate=True))
|
173
|
-
else:
|
174
|
-
logging.info(
|
175
|
-
f"[{self.name}] Research evaluation failed or not found. Loop will continue."
|
176
|
-
)
|
177
|
-
# Yielding an event without content or actions just lets the flow continue.
|
178
|
-
yield Event(author=self.name)
|
179
|
-
|
180
|
-
|
181
|
-
# --- AGENT DEFINITIONS ---
|
182
|
-
plan_generator = LlmAgent(
|
183
|
-
model=config.worker_model,
|
184
|
-
name="plan_generator",
|
185
|
-
description="Generates or refine the existing 5 line action-oriented research plan, using minimal search only for topic clarification.",
|
186
|
-
instruction=f"""
|
187
|
-
You are a research strategist. Your job is to create a high-level RESEARCH PLAN, not a summary. If there is already a RESEARCH PLAN in the session state,
|
188
|
-
improve upon it based on the user feedback.
|
189
|
-
|
190
|
-
RESEARCH PLAN(SO FAR):
|
191
|
-
{{ research_plan? }}
|
192
|
-
|
193
|
-
**GENERAL INSTRUCTION: CLASSIFY TASK TYPES**
|
194
|
-
Your plan must clearly classify each goal for downstream execution. Each bullet point should start with a task type prefix:
|
195
|
-
- **`[RESEARCH]`**: For goals that primarily involve information gathering, investigation, analysis, or data collection (these require search tool usage by a researcher).
|
196
|
-
- **`[DELIVERABLE]`**: For goals that involve synthesizing collected information, creating structured outputs (e.g., tables, charts, summaries, reports), or compiling final output artifacts (these are executed AFTER research tasks, often without further search).
|
197
|
-
|
198
|
-
**INITIAL RULE: Your initial output MUST start with a bulleted list of 5 action-oriented research goals or key questions, followed by any *inherently implied* deliverables.**
|
199
|
-
- All initial 5 goals will be classified as `[RESEARCH]` tasks.
|
200
|
-
- A good goal for `[RESEARCH]` starts with a verb like "Analyze," "Identify," "Investigate."
|
201
|
-
- A bad output is a statement of fact like "The event was in April 2024."
|
202
|
-
- **Proactive Implied Deliverables (Initial):** If any of your initial 5 `[RESEARCH]` goals inherently imply a standard output or deliverable (e.g., a comparative analysis suggesting a comparison table, or a comprehensive review suggesting a summary document), you MUST add these as additional, distinct goals immediately after the initial 5. Phrase these as *synthesis or output creation actions* (e.g., "Create a summary," "Develop a comparison," "Compile a report") and prefix them with `[DELIVERABLE][IMPLIED]`.
|
203
|
-
|
204
|
-
**REFINEMENT RULE**:
|
205
|
-
- **Integrate Feedback & Mark Changes:** When incorporating user feedback, make targeted modifications to existing bullet points. Add `[MODIFIED]` to the existing task type and status prefix (e.g., `[RESEARCH][MODIFIED]`). If the feedback introduces new goals:
|
206
|
-
- If it's an information gathering task, prefix it with `[RESEARCH][NEW]`.
|
207
|
-
- If it's a synthesis or output creation task, prefix it with `[DELIVERABLE][NEW]`.
|
208
|
-
- **Proactive Implied Deliverables (Refinement):** Beyond explicit user feedback, if the nature of an existing `[RESEARCH]` goal (e.g., requiring a structured comparison, deep dive analysis, or broad synthesis) or a `[DELIVERABLE]` goal inherently implies an additional, standard output or synthesis step (e.g., a detailed report following a summary, or a visual representation of complex data), proactively add this as a new goal. Phrase these as *synthesis or output creation actions* and prefix them with `[DELIVERABLE][IMPLIED]`.
|
209
|
-
- **Maintain Order:** Strictly maintain the original sequential order of existing bullet points. New bullets, whether `[NEW]` or `[IMPLIED]`, should generally be appended to the list, unless the user explicitly instructs a specific insertion point.
|
210
|
-
- **Flexible Length:** The refined plan is no longer constrained by the initial 5-bullet limit and may comprise more goals as needed to fully address the feedback and implied deliverables.
|
211
|
-
|
212
|
-
**TOOL USE IS STRICTLY LIMITED:**
|
213
|
-
Your goal is to create a generic, high-quality plan *without searching*.
|
214
|
-
Only use `google_search` if a topic is ambiguous or time-sensitive and you absolutely cannot create a plan without a key piece of identifying information.
|
215
|
-
You are explicitly forbidden from researching the *content* or *themes* of the topic. That is the next agent's job. Your search is only to identify the subject, not to investigate it.
|
216
|
-
Current date: {datetime.datetime.now().strftime("%Y-%m-%d")}
|
217
|
-
""",
|
218
|
-
tools=[google_search],
|
219
|
-
)
|
220
|
-
|
221
|
-
|
222
|
-
section_planner = LlmAgent(
|
223
|
-
model=config.worker_model,
|
224
|
-
name="section_planner",
|
225
|
-
description="Breaks down the research plan into a structured markdown outline of report sections.",
|
226
|
-
instruction="""
|
227
|
-
You are an expert report architect. Using the research topic and the plan from the 'research_plan' state key, design a logical structure for the final report.
|
228
|
-
Note: Ignore all the tag nanes ([MODIFIED], [NEW], [RESEARCH], [DELIVERABLE]) in the research plan.
|
229
|
-
Your task is to create a markdown outline with 4-6 distinct sections that cover the topic comprehensively without overlap.
|
230
|
-
You can use any markdown format you prefer, but here's a suggested structure:
|
231
|
-
# Section Name
|
232
|
-
A brief overview of what this section covers
|
233
|
-
Feel free to add subsections or bullet points if needed to better organize the content.
|
234
|
-
Make sure your outline is clear and easy to follow.
|
235
|
-
Do not include a "References" or "Sources" section in your outline. Citations will be handled in-line.
|
236
|
-
""",
|
237
|
-
output_key="report_sections",
|
238
|
-
)
|
239
|
-
|
240
|
-
|
241
|
-
section_researcher = LlmAgent(
|
242
|
-
model=config.worker_model,
|
243
|
-
name="section_researcher",
|
244
|
-
description="Performs the crucial first pass of web research.",
|
245
|
-
planner=BuiltInPlanner(
|
246
|
-
thinking_config=genai_types.ThinkingConfig(include_thoughts=True)
|
247
|
-
),
|
248
|
-
instruction="""
|
249
|
-
You are a highly capable and diligent research and synthesis agent. Your comprehensive task is to execute a provided research plan with **absolute fidelity**, first by gathering necessary information, and then by synthesizing that information into specified outputs.
|
250
|
-
|
251
|
-
You will be provided with a sequential list of research plan goals, stored in the `research_plan` state key. Each goal will be clearly prefixed with its primary task type: `[RESEARCH]` or `[DELIVERABLE]`.
|
252
|
-
|
253
|
-
Your execution process must strictly adhere to these two distinct and sequential phases:
|
254
|
-
|
255
|
-
---
|
256
|
-
|
257
|
-
**Phase 1: Information Gathering (`[RESEARCH]` Tasks)**
|
258
|
-
|
259
|
-
* **Execution Directive:** You **MUST** systematically process every goal prefixed with `[RESEARCH]` before proceeding to Phase 2.
|
260
|
-
* For each `[RESEARCH]` goal:
|
261
|
-
* **Query Generation:** Formulate a comprehensive set of 4-5 targeted search queries. These queries must be expertly designed to broadly cover the specific intent of the `[RESEARCH]` goal from multiple angles.
|
262
|
-
* **Execution:** Utilize the `google_search` tool to execute **all** generated queries for the current `[RESEARCH]` goal.
|
263
|
-
* **Summarization:** Synthesize the search results into a detailed, coherent summary that directly addresses the objective of the `[RESEARCH]` goal.
|
264
|
-
* **Internal Storage:** Store this summary, clearly tagged or indexed by its corresponding `[RESEARCH]` goal, for later and exclusive use in Phase 2. You **MUST NOT** lose or discard any generated summaries.
|
265
|
-
|
266
|
-
---
|
267
|
-
|
268
|
-
**Phase 2: Synthesis and Output Creation (`[DELIVERABLE]` Tasks)**
|
269
|
-
|
270
|
-
* **Execution Prerequisite:** This phase **MUST ONLY COMMENCE** once **ALL** `[RESEARCH]` goals from Phase 1 have been fully completed and their summaries are internally stored.
|
271
|
-
* **Execution Directive:** You **MUST** systematically process **every** goal prefixed with `[DELIVERABLE]`. For each `[DELIVERABLE]` goal, your directive is to **PRODUCE** the artifact as explicitly described.
|
272
|
-
* For each `[DELIVERABLE]` goal:
|
273
|
-
* **Instruction Interpretation:** You will interpret the goal's text (following the `[DELIVERABLE]` tag) as a **direct and non-negotiable instruction** to generate a specific output artifact.
|
274
|
-
* *If the instruction details a table (e.g., "Create a Detailed Comparison Table in Markdown format"), your output for this step **MUST** be a properly formatted Markdown table utilizing columns and rows as implied by the instruction and the prepared data.*
|
275
|
-
* *If the instruction states to prepare a summary, report, or any other structured output, your output for this step **MUST** be that precise artifact.*
|
276
|
-
* **Data Consolidation:** Access and utilize **ONLY** the summaries generated during Phase 1 (`[RESEARCH]` tasks`) to fulfill the requirements of the current `[DELIVERABLE]` goal. You **MUST NOT** perform new searches.
|
277
|
-
* **Output Generation:** Based on the specific instruction of the `[DELIVERABLE]` goal:
|
278
|
-
* Carefully extract, organize, and synthesize the relevant information from your previously gathered summaries.
|
279
|
-
* Must always produce the specified output artifact (e.g., a concise summary, a structured comparison table, a comprehensive report, a visual representation, etc.) with accuracy and completeness.
|
280
|
-
* **Output Accumulation:** Maintain and accumulate **all** the generated `[DELIVERABLE]` artifacts. These are your final outputs.
|
281
|
-
|
282
|
-
---
|
283
|
-
|
284
|
-
**Final Output:** Your final output will comprise the complete set of processed summaries from `[RESEARCH]` tasks AND all the generated artifacts from `[DELIVERABLE]` tasks, presented clearly and distinctly.
|
285
|
-
""",
|
286
|
-
tools=[google_search],
|
287
|
-
output_key="section_research_findings",
|
288
|
-
after_agent_callback=collect_research_sources_callback,
|
289
|
-
)
|
290
|
-
|
291
|
-
research_evaluator = LlmAgent(
|
292
|
-
model=config.critic_model,
|
293
|
-
name="research_evaluator",
|
294
|
-
description="Critically evaluates research and generates follow-up queries.",
|
295
|
-
instruction=f"""
|
296
|
-
You are a meticulous quality assurance analyst evaluating the research findings in 'section_research_findings'.
|
297
|
-
|
298
|
-
**CRITICAL RULES:**
|
299
|
-
1. Assume the given research topic is correct. Do not question or try to verify the subject itself.
|
300
|
-
2. Your ONLY job is to assess the quality, depth, and completeness of the research provided *for that topic*.
|
301
|
-
3. Focus on evaluating: Comprehensiveness of coverage, logical flow and organization, use of credible sources, depth of analysis, and clarity of explanations.
|
302
|
-
4. Do NOT fact-check or question the fundamental premise or timeline of the topic.
|
303
|
-
5. If suggesting follow-up queries, they should dive deeper into the existing topic, not question its validity.
|
304
|
-
|
305
|
-
Be very critical about the QUALITY of research. If you find significant gaps in depth or coverage, assign a grade of "fail",
|
306
|
-
write a detailed comment about what's missing, and generate 5-7 specific follow-up queries to fill those gaps.
|
307
|
-
If the research thoroughly covers the topic, grade "pass".
|
308
|
-
|
309
|
-
Current date: {datetime.datetime.now().strftime("%Y-%m-%d")}
|
310
|
-
Your response must be a single, raw JSON object validating against the 'Feedback' schema.
|
311
|
-
""",
|
312
|
-
output_schema=Feedback,
|
313
|
-
disallow_transfer_to_parent=True,
|
314
|
-
disallow_transfer_to_peers=True,
|
315
|
-
output_key="research_evaluation",
|
316
|
-
)
|
317
|
-
|
318
|
-
enhanced_search_executor = LlmAgent(
|
319
|
-
model=config.worker_model,
|
320
|
-
name="enhanced_search_executor",
|
321
|
-
description="Executes follow-up searches and integrates new findings.",
|
322
|
-
planner=BuiltInPlanner(
|
323
|
-
thinking_config=genai_types.ThinkingConfig(include_thoughts=True)
|
324
|
-
),
|
325
|
-
instruction="""
|
326
|
-
You are a specialist researcher executing a refinement pass.
|
327
|
-
You have been activated because the previous research was graded as 'fail'.
|
328
|
-
|
329
|
-
1. Review the 'research_evaluation' state key to understand the feedback and required fixes.
|
330
|
-
2. Execute EVERY query listed in 'follow_up_queries' using the 'google_search' tool.
|
331
|
-
3. Synthesize the new findings and COMBINE them with the existing information in 'section_research_findings'.
|
332
|
-
4. Your output MUST be the new, complete, and improved set of research findings.
|
333
|
-
""",
|
334
|
-
tools=[google_search],
|
335
|
-
output_key="section_research_findings",
|
336
|
-
after_agent_callback=collect_research_sources_callback,
|
337
|
-
)
|
338
|
-
|
339
|
-
report_composer = LlmAgent(
|
340
|
-
model=config.critic_model,
|
341
|
-
name="report_composer_with_citations",
|
342
|
-
include_contents="none",
|
343
|
-
description="Transforms research data and a markdown outline into a final, cited report.",
|
344
|
-
instruction="""
|
345
|
-
Transform the provided data into a polished, professional, and meticulously cited research report.
|
346
|
-
|
347
|
-
---
|
348
|
-
### INPUT DATA
|
349
|
-
* Research Plan: `{research_plan}`
|
350
|
-
* Research Findings: `{section_research_findings}`
|
351
|
-
* Citation Sources: `{sources}`
|
352
|
-
* Report Structure: `{report_sections}`
|
353
|
-
|
354
|
-
---
|
355
|
-
### CRITICAL: Citation System
|
356
|
-
To cite a source, you MUST insert a special citation tag directly after the claim it supports.
|
357
|
-
|
358
|
-
**The only correct format is:** `<cite source="src-ID_NUMBER" />`
|
359
|
-
|
360
|
-
---
|
361
|
-
### Final Instructions
|
362
|
-
Generate a comprehensive report using ONLY the `<cite source="src-ID_NUMBER" />` tag system for all citations.
|
363
|
-
The final report must strictly follow the structure provided in the **Report Structure** markdown outline.
|
364
|
-
Do not include a "References" or "Sources" section; all citations must be in-line.
|
365
|
-
""",
|
366
|
-
output_key="final_cited_report",
|
367
|
-
after_agent_callback=citation_replacement_callback,
|
368
|
-
)
|
369
|
-
|
370
|
-
research_pipeline = SequentialAgent(
|
371
|
-
name="research_pipeline",
|
372
|
-
description="Executes a pre-approved research plan. It performs iterative research, evaluation, and composes a final, cited report.",
|
373
|
-
sub_agents=[
|
374
|
-
section_planner,
|
375
|
-
section_researcher,
|
376
|
-
LoopAgent(
|
377
|
-
name="iterative_refinement_loop",
|
378
|
-
max_iterations=config.max_search_iterations,
|
379
|
-
sub_agents=[
|
380
|
-
research_evaluator,
|
381
|
-
EscalationChecker(name="escalation_checker"),
|
382
|
-
enhanced_search_executor,
|
383
|
-
],
|
384
|
-
),
|
385
|
-
report_composer,
|
386
|
-
],
|
387
|
-
)
|
388
|
-
|
389
|
-
interactive_planner_agent = LlmAgent(
|
390
|
-
name="interactive_planner_agent",
|
391
|
-
model=config.worker_model,
|
392
|
-
description="The primary research assistant. It collaborates with the user to create a research plan, and then executes it upon approval.",
|
393
|
-
instruction=f"""
|
394
|
-
You are a research planning assistant. Your primary function is to convert ANY user request into a research plan.
|
395
|
-
|
396
|
-
**CRITICAL RULE: Never answer a question directly or refuse a request.** Your one and only first step is to use the `plan_generator` tool to propose a research plan for the user's topic.
|
397
|
-
If the user asks a question, you MUST immediately call `plan_generator` to create a plan to answer the question.
|
398
|
-
|
399
|
-
Your workflow is:
|
400
|
-
1. **Plan:** Use `plan_generator` to create a draft plan and present it to the user.
|
401
|
-
2. **Refine:** Incorporate user feedback until the plan is approved.
|
402
|
-
3. **Execute:** Once the user gives EXPLICIT approval (e.g., "looks good, run it"), you MUST delegate the task to the `research_pipeline` agent, passing the approved plan.
|
403
|
-
|
404
|
-
Current date: {datetime.datetime.now().strftime("%Y-%m-%d")}
|
405
|
-
Do not perform any research yourself. Your job is to Plan, Refine, and Delegate.
|
406
|
-
""",
|
407
|
-
sub_agents=[research_pipeline],
|
408
|
-
tools=[AgentTool(plan_generator)],
|
409
|
-
output_key="research_plan",
|
410
|
-
)
|
411
|
-
|
412
|
-
root_agent = interactive_planner_agent
|
@@ -1,46 +0,0 @@
|
|
1
|
-
# Copyright 2025 Google LLC
|
2
|
-
#
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
-
# you may not use this file except in compliance with the License.
|
5
|
-
# You may obtain a copy of the License at
|
6
|
-
#
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
-
#
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
-
# See the License for the specific language governing permissions and
|
13
|
-
# limitations under the License.
|
14
|
-
|
15
|
-
import os
|
16
|
-
from dataclasses import dataclass
|
17
|
-
|
18
|
-
import google.auth
|
19
|
-
|
20
|
-
# To use AI Studio credentials:
|
21
|
-
# 1. Create a .env file in the /app directory with:
|
22
|
-
# GOOGLE_GENAI_USE_VERTEXAI=FALSE
|
23
|
-
# GOOGLE_API_KEY=PASTE_YOUR_ACTUAL_API_KEY_HERE
|
24
|
-
# 2. This will override the default Vertex AI configuration
|
25
|
-
_, project_id = google.auth.default()
|
26
|
-
os.environ.setdefault("GOOGLE_CLOUD_PROJECT", project_id)
|
27
|
-
os.environ.setdefault("GOOGLE_CLOUD_LOCATION", "global")
|
28
|
-
os.environ.setdefault("GOOGLE_GENAI_USE_VERTEXAI", "True")
|
29
|
-
|
30
|
-
|
31
|
-
@dataclass
|
32
|
-
class ResearchConfiguration:
|
33
|
-
"""Configuration for research-related models and parameters.
|
34
|
-
|
35
|
-
Attributes:
|
36
|
-
critic_model (str): Model for evaluation tasks.
|
37
|
-
worker_model (str): Model for working/generation tasks.
|
38
|
-
max_search_iterations (int): Maximum search iterations allowed.
|
39
|
-
"""
|
40
|
-
|
41
|
-
critic_model: str = "gemini-2.5-pro"
|
42
|
-
worker_model: str = "gemini-2.5-flash"
|
43
|
-
max_search_iterations: int = 5
|
44
|
-
|
45
|
-
|
46
|
-
config = ResearchConfiguration()
|