Phase Annotation¶
Complex agents often work in distinct stages — researching, then planning, then executing. Phase Annotation provides structured context scoping for these stages using Python's async with syntax.
The mechanism is self.snapshot — it creates a scoped context where think units run, and automatically restores the original state on exit. Think of it as a save/restore point: the agent enters a phase with overridden fields (e.g., a new goal), works within that scope, and when done, everything reverts as if the phase never touched the outer context.
Initialize¶
import os
model_name = os.environ.get("MODEL_NAME")
api_key = os.environ.get("API_KEY")
api_base = os.environ.get("BASE_URL")
from bridgic.llms.openai import OpenAILlm, OpenAIConfiguration
llm = OpenAILlm(
api_key=api_key,
api_base=api_base,
timeout=120,
configuration=OpenAIConfiguration(
model=model_name,
temperature=0.0,
max_tokens=16384,
),
)
from bridgic.core.agentic.tool_specs import FunctionToolSpec
async def research_topic(topic: str) -> str:
"""Search for information about a topic"""
return f"Research results for '{topic}': Found 5 relevant sources with key insights."
async def create_outline(title: str, research: str) -> str:
"""Create an outline for an article"""
return f"Outline for '{title}': Introduction, 3 main sections, conclusion"
async def write_section(title: str, section: str, notes: str) -> str:
"""Write an article section based on outline and research"""
return f"Written section '{section}' for '{title}' ({len(notes)} chars of notes used)"
async def edit_article(title: str, edit_instructions: str) -> str:
"""Edit an existing article to fix issues"""
return f"Edited '{title}': Applied changes — {edit_instructions}"
research_topic_tool = FunctionToolSpec.from_raw(research_topic)
create_outline_tool = FunctionToolSpec.from_raw(create_outline)
write_section_tool = FunctionToolSpec.from_raw(write_section)
edit_article_tool = FunctionToolSpec.from_raw(edit_article)
Snapshot — Scoped Context Override¶
async with self.snapshot(goal="...", **fields) is the fundamental context scoping mechanism in Phase Annotation.
Here's what it does:
- On enter — saves the current context state, then applies your overrides (goal, or any other context field)
- During execution — all think units inside the block see the overridden context. The LLM receives the snapshot's goal, not the original one
- On exit — restores all original field values, as if the snapshot block never happened
Snapshot also manages LayeredExposure state (skills, cognitive_history): it clears any previously revealed details on enter, so the LLM starts fresh in each phase. On exit, the pre-snapshot revealed state is restored.
This makes snapshot ideal for:
- Breaking a large task into focused sub-goals
- Handling interruptions without losing the outer context
- Scoping what the LLM "knows" in each phase
Snapshot Lifecycle¶
async with self.snapshot(goal="Sub-task A"):
├─ save original fields
├─ apply overrides (goal → "Sub-task A")
├─ clear LayeredExposure revealed state
│
await self.worker ← LLM sees goal = "Sub-task A"
│
└─ restore original fields + revealed state
# Here, context.goal is back to the original
Example: Multi-Phase Content Creation¶
Let's build an agent that works in two scoped phases — research, then writing. Each phase has its own goal, so the LLM focuses on one thing at a time.
from bridgic.amphibious import (
AmphibiousAutoma, CognitiveContext, CognitiveWorker, think_unit
)
class ContentCreator(AmphibiousAutoma[CognitiveContext]):
researcher = think_unit(
CognitiveWorker.inline(
"Research the topic thoroughly. Gather key facts and sources.",
verbose_prompt=True,
),
max_attempts=3,
)
writer = think_unit(
CognitiveWorker.inline(
"Write the article based on the research gathered so far.",
verbose_prompt=True,
),
max_attempts=5,
)
async def on_agent(self, ctx: CognitiveContext):
# Phase 1: Research — LLM sees goal = "Gather research material..."
async with self.snapshot(goal="Gather research material on renewable energy"):
await self.researcher
# Phase 2: Write — LLM sees goal = "Write the article..."
async with self.snapshot(goal="Write the article using the gathered research"):
await self.writer
agent = ContentCreator(llm=llm, verbose=True)
result = await agent.arun(
goal="Write an article about the future of renewable energy",
tools=[research_topic_tool, create_outline_tool, write_section_tool],
)
print(result)
[18:36:34.976] [Router] (_amphibious_automa.py:1573) Auto-detecting execution mode [18:36:34.976] [Router] (_amphibious_automa.py:1579) Detected AGENT mode [18:36:34.977] [Observe] (_amphibious_automa.py:861) _PromptWorker: None [18:36:40.473] [Think] (_cognitive_worker.py:332) Message 1 (system, 348 tokens): Research the topic thoroughly. Gather key facts and sources.Respond in JSON format. # Available Tools (with parameters): • research_topic: Search for information about a topic - topic (string) [required] • create_outline: Create an outline for an article - title (string) [required] - research (string) [required] • write_section: Write an article section based on outline and research - title (string) [required] - section (string) [required] - notes (string) [required] # Context Acquiring If the context contains progressively disclosed information (e.g. skills, history steps) and you want to inspect the details, use the **details** field to request them. The framework will expand these items in the next round. Batch all requests in a single output. When using this field, leave step_content and output empty. ## Field format: - **details**: [{field: "skills", index: 0}, ...] Available fields: **skills** (view a skill's full workflow), **cognitive_history** (view the full result of a previous step) # Output Fields - **step_content**: Your analysis and reasoning for this step - **finish**: Set True when the sub-task is fully complete (default: False) - **details**: Available fields: **skills**, **cognitive_history**. example: [{field: 'skills', index: 0}, ...] - **output**: Tool calls to execute: [{tool, tool_arguments: [{name: 'param', value: 'value'}]}] [18:36:40.473] [Think] (_cognitive_worker.py:332) Message 2 (user, 33 tokens): Based on the context below, decide your next action. Goal: Gather research material on renewable energy Execution History: (none) [18:36:40.473] [Think] (_cognitive_worker.py:332) Total: 381 tokens (cumulative: 381) [18:36:40.475] [Think] (_amphibious_automa.py:867) _PromptWorker: finish=False, step=Starting the research process on renewable energy. This is the first step, so I need to gather comprehensive information about the topic using the research_topic tool. This will provide the foundation for creating an outline and writing sections later. [18:36:40.477] [Act] (_amphibious_automa.py:873) _PromptWorker: { "content": "Starting the research process on renewable energy. This is the first step, so I need to gather comprehensive information about the topic using the research_topic tool. This will provide the foundation for creating an outline and writing sections later.", "result": { "results": [ { "tool_id": "call_0", "tool_name": "research_topic", "tool_arguments": { "topic": "renewable energy" }, "tool_result": "Research results for 'renewable energy': Found 5 relevant sources with key insights.", "success": true, "error": null } ] }, "metadata": {}, "status": null } [18:36:40.478] [Observe] (_amphibious_automa.py:861) _PromptWorker: None [18:36:50.135] [Think] (_cognitive_worker.py:332) Message 1 (system, 348 tokens): Research the topic thoroughly. Gather key facts and sources.Respond in JSON format. # Available Tools (with parameters): • research_topic: Search for information about a topic - topic (string) [required] • create_outline: Create an outline for an article - title (string) [required] - research (string) [required] • write_section: Write an article section based on outline and research - title (string) [required] - section (string) [required] - notes (string) [required] # Context Acquiring If the context contains progressively disclosed information (e.g. skills, history steps) and you want to inspect the details, use the **details** field to request them. The framework will expand these items in the next round. Batch all requests in a single output. When using this field, leave step_content and output empty. ## Field format: - **details**: [{field: "skills", index: 0}, ...] Available fields: **skills** (view a skill's full workflow), **cognitive_history** (view the full result of a previous step) # Output Fields - **step_content**: Your analysis and reasoning for this step - **finish**: Set True when the sub-task is fully complete (default: False) - **details**: Available fields: **skills**, **cognitive_history**. example: [{field: 'skills', index: 0}, ...] - **output**: Tool calls to execute: [{tool, tool_arguments: [{name: 'param', value: 'value'}]}] [18:36:50.135] [Think] (_cognitive_worker.py:332) Message 2 (user, 167 tokens): Based on the context below, decide your next action. Goal: Gather research material on renewable energy Execution History: [Working Memory (0-0)] [0] Starting the research process on renewable energy. This is the first step, so I need to gather comprehensive information about the topic using the research_topic tool. This will provide the foundation for creating an outline and writing sections later. Result: results=[ActionStepResult(tool_id='call_0', tool_name='research_topic', tool_arguments={'topic': 'renewable energy'}, tool_result="Research results for 'renewable energy': Found 5 relevant sources with key insights.", success=True, error=None)] [18:36:50.135] [Think] (_cognitive_worker.py:332) Total: 515 tokens (cumulative: 896) [18:36:50.138] [Think] (_amphibious_automa.py:867) _PromptWorker: finish=False, step=The initial research on renewable energy was successful, finding 5 relevant sources. However, to gather comprehensive research material, I need to dive deeper into specific renewable energy types. I'll conduct additional research on the main categories of renewable energy: solar, wind, hydroelectric, geothermal, and biomass. This will provide detailed information for each major renewable energy source. [18:36:50.141] [Act] (_amphibious_automa.py:873) _PromptWorker: { "content": "The initial research on renewable energy was successful, finding 5 relevant sources. However, to gather comprehensive research material, I need to dive deeper into specific renewable energy types. I'll conduct additional research on the main categories of renewable energy: solar, wind, hydroelectric, geothermal, and biomass. This will provide detailed information for each major renewable energy source.", "result": { "results": [ { "tool_id": "call_0", "tool_name": "research_topic", "tool_arguments": { "topic": "biomass energy" }, "tool_result": "Research results for 'biomass energy': Found 5 relevant sources with key insights.", "success": true, "error": null } ] }, "metadata": {}, "status": null } [18:36:50.141] [Observe] (_amphibious_automa.py:861) _PromptWorker: None [18:36:57.440] [Think] (_cognitive_worker.py:332) Message 1 (system, 348 tokens): Research the topic thoroughly. Gather key facts and sources.Respond in JSON format. # Available Tools (with parameters): • research_topic: Search for information about a topic - topic (string) [required] • create_outline: Create an outline for an article - title (string) [required] - research (string) [required] • write_section: Write an article section based on outline and research - title (string) [required] - section (string) [required] - notes (string) [required] # Context Acquiring If the context contains progressively disclosed information (e.g. skills, history steps) and you want to inspect the details, use the **details** field to request them. The framework will expand these items in the next round. Batch all requests in a single output. When using this field, leave step_content and output empty. ## Field format: - **details**: [{field: "skills", index: 0}, ...] Available fields: **skills** (view a skill's full workflow), **cognitive_history** (view the full result of a previous step) # Output Fields - **step_content**: Your analysis and reasoning for this step - **finish**: Set True when the sub-task is fully complete (default: False) - **details**: Available fields: **skills**, **cognitive_history**. example: [{field: 'skills', index: 0}, ...] - **output**: Tool calls to execute: [{tool, tool_arguments: [{name: 'param', value: 'value'}]}] [18:36:57.440] [Think] (_cognitive_worker.py:332) Message 2 (user, 333 tokens): Based on the context below, decide your next action. Goal: Gather research material on renewable energy Execution History: [Working Memory (0-1)] [0] Starting the research process on renewable energy. This is the first step, so I need to gather comprehensive information about the topic using the research_topic tool. This will provide the foundation for creating an outline and writing sections later. Result: results=[ActionStepResult(tool_id='call_0', tool_name='research_topic', tool_arguments={'topic': 'renewable energy'}, tool_result="Research results for 'renewable energy': Found 5 relevant sources with key insights.", success=True, error=None)] [1] The initial research on renewable energy was successful, finding 5 relevant sources. However, to gather comprehensive research material, I need to dive deeper into specific renewable energy types. I'll conduct additional research on the main categories of renewable energy: solar, wind, hydroelectric, geothermal, and biomass. This will provide detailed information for each major renewable energy source. Result: results=[ActionStepResult(tool_id='call_0', tool_name='research_topic', tool_arguments={'topic': 'biomass energy'}, tool_result="Research results for 'biomass energy': Found 5 relevant sources with key insights.", success=True, error=None)] [18:36:57.440] [Think] (_cognitive_worker.py:332) Total: 681 tokens (cumulative: 1577) [18:36:57.443] [Think] (_amphibious_automa.py:867) _PromptWorker: finish=False, step=Based on the execution history, I've successfully completed initial research on 'renewable energy' (Step 0) and 'biomass energy' (Step 1). To gather comprehensive research material on renewable energy, I need to continue researching the other major renewable energy types mentioned in Step 1's reasoning: solar, wind, hydroelectric, and geothermal. I'll batch these research calls to efficiently gather information on all remaining categories. [18:36:57.446] [Act] (_amphibious_automa.py:873) _PromptWorker: { "content": "Based on the execution history, I've successfully completed initial research on 'renewable energy' (Step 0) and 'biomass energy' (Step 1). To gather comprehensive research material on renewable energy, I need to continue researching the other major renewable energy types mentioned in Step 1's reasoning: solar, wind, hydroelectric, and geothermal. I'll batch these research calls to efficiently gather information on all remaining categories.", "result": { "results": [ { "tool_id": "call_0", "tool_name": "research_topic", "tool_arguments": { "topic": "geothermal energy" }, "tool_result": "Research results for 'geothermal energy': Found 5 relevant sources with key insights.", "success": true, "error": null } ] }, "metadata": {}, "status": null } [18:36:57.446] [Observe] (_amphibious_automa.py:861) _PromptWorker: None [18:37:19.937] [Think] (_cognitive_worker.py:332) Message 1 (system, 347 tokens): Write the article based on the research gathered so far.Respond in JSON format. # Available Tools (with parameters): • research_topic: Search for information about a topic - topic (string) [required] • create_outline: Create an outline for an article - title (string) [required] - research (string) [required] • write_section: Write an article section based on outline and research - title (string) [required] - section (string) [required] - notes (string) [required] # Context Acquiring If the context contains progressively disclosed information (e.g. skills, history steps) and you want to inspect the details, use the **details** field to request them. The framework will expand these items in the next round. Batch all requests in a single output. When using this field, leave step_content and output empty. ## Field format: - **details**: [{field: "skills", index: 0}, ...] Available fields: **skills** (view a skill's full workflow), **cognitive_history** (view the full result of a previous step) # Output Fields - **step_content**: Your analysis and reasoning for this step - **finish**: Set True when the sub-task is fully complete (default: False) - **details**: Available fields: **skills**, **cognitive_history**. example: [{field: 'skills', index: 0}, ...] - **output**: Tool calls to execute: [{tool, tool_arguments: [{name: 'param', value: 'value'}]}] [18:37:19.937] [Think] (_cognitive_worker.py:332) Message 2 (user, 511 tokens): Based on the context below, decide your next action. Goal: Write the article using the gathered research Execution History: [Working Memory (0-2)] [0] Starting the research process on renewable energy. This is the first step, so I need to gather comprehensive information about the topic using the research_topic tool. This will provide the foundation for creating an outline and writing sections later. Result: results=[ActionStepResult(tool_id='call_0', tool_name='research_topic', tool_arguments={'topic': 'renewable energy'}, tool_result="Research results for 'renewable energy': Found 5 relevant sources with key insights.", success=True, error=None)] [1] The initial research on renewable energy was successful, finding 5 relevant sources. However, to gather comprehensive research material, I need to dive deeper into specific renewable energy types. I'll conduct additional research on the main categories of renewable energy: solar, wind, hydroelectric, geothermal, and biomass. This will provide detailed information for each major renewable energy source. Result: results=[ActionStepResult(tool_id='call_0', tool_name='research_topic', tool_arguments={'topic': 'biomass energy'}, tool_result="Research results for 'biomass energy': Found 5 relevant sources with key insights.", success=True, error=None)] [2] Based on the execution history, I've successfully completed initial research on 'renewable energy' (Step 0) and 'biomass energy' (Step 1). To gather comprehensive research material on renewable energy, I need to continue researching the other major renewable energy types mentioned in Step 1's reasoning: solar, wind, hydroelectric, and geothermal. I'll batch these research calls to efficiently gather information on all remaining categories. Result: results=[ActionStepResult(tool_id='call_0', tool_name='research_topic', tool_arguments={'topic': 'geothermal energy'}, tool_result="Research results for 'geothermal energy': Found 5 relevant sources with key insights.", success=True, error=None)] [18:37:19.937] [Think] (_cognitive_worker.py:332) Total: 858 tokens (cumulative: 858) [18:37:19.940] [Think] (_amphibious_automa.py:867) _PromptWorker: finish=False, step=Now that research on renewable energy, biomass, and geothermal energy has been completed, the next step is to create a structured outline for the article. This outline will organize the gathered research into coherent sections, ensuring comprehensive coverage of the topic while highlighting key insights from each energy type. The outline will serve as the foundation for writing individual sections. [18:37:19.942] [Act] (_amphibious_automa.py:873) _PromptWorker: { "content": "Now that research on renewable energy, biomass, and geothermal energy has been completed, the next step is to create a structured outline for the article. This outline will organize the gathered research into coherent sections, ensuring comprehensive coverage of the topic while highlighting key insights from each energy type. The outline will serve as the foundation for writing individual sections.", "result": { "results": [ { "tool_id": "call_0", "tool_name": "create_outline", "tool_arguments": { "title": "Renewable Energy: Types, Benefits, and Future Prospects", "research": "Research includes general renewable energy overview (5 sources), biomass energy details (5 sources), and geothermal energy insights (5 sources). Key themes: sustainability, technological advancements, environmental impact, and global adoption trends." }, "tool_result": "Outline for 'Renewable Energy: Types, Benefits, and Future Prospects': Introduction, 3 main sections, conclusion", "success": true, "error": null } ] }, "metadata": {}, "status": null } [18:37:19.943] [Observe] (_amphibious_automa.py:861) _PromptWorker: None [18:37:36.795] [Think] (_cognitive_worker.py:332) Message 1 (system, 347 tokens): Write the article based on the research gathered so far.Respond in JSON format. # Available Tools (with parameters): • research_topic: Search for information about a topic - topic (string) [required] • create_outline: Create an outline for an article - title (string) [required] - research (string) [required] • write_section: Write an article section based on outline and research - title (string) [required] - section (string) [required] - notes (string) [required] # Context Acquiring If the context contains progressively disclosed information (e.g. skills, history steps) and you want to inspect the details, use the **details** field to request them. The framework will expand these items in the next round. Batch all requests in a single output. When using this field, leave step_content and output empty. ## Field format: - **details**: [{field: "skills", index: 0}, ...] Available fields: **skills** (view a skill's full workflow), **cognitive_history** (view the full result of a previous step) # Output Fields - **step_content**: Your analysis and reasoning for this step - **finish**: Set True when the sub-task is fully complete (default: False) - **details**: Available fields: **skills**, **cognitive_history**. example: [{field: 'skills', index: 0}, ...] - **output**: Tool calls to execute: [{tool, tool_arguments: [{name: 'param', value: 'value'}]}] [18:37:36.795] [Think] (_cognitive_worker.py:332) Message 2 (user, 742 tokens): Based on the context below, decide your next action. Goal: Write the article using the gathered research Execution History: [Working Memory (0-3)] [0] Starting the research process on renewable energy. This is the first step, so I need to gather comprehensive information about the topic using the research_topic tool. This will provide the foundation for creating an outline and writing sections later. Result: results=[ActionStepResult(tool_id='call_0', tool_name='research_topic', tool_arguments={'topic': 'renewable energy'}, tool_result="Research results for 'renewable energy': Found 5 relevant sources with key insights.", success=True, error=None)] [1] The initial research on renewable energy was successful, finding 5 relevant sources. However, to gather comprehensive research material, I need to dive deeper into specific renewable energy types. I'll conduct additional research on the main categories of renewable energy: solar, wind, hydroelectric, geothermal, and biomass. This will provide detailed information for each major renewable energy source. Result: results=[ActionStepResult(tool_id='call_0', tool_name='research_topic', tool_arguments={'topic': 'biomass energy'}, tool_result="Research results for 'biomass energy': Found 5 relevant sources with key insights.", success=True, error=None)] [2] Based on the execution history, I've successfully completed initial research on 'renewable energy' (Step 0) and 'biomass energy' (Step 1). To gather comprehensive research material on renewable energy, I need to continue researching the other major renewable energy types mentioned in Step 1's reasoning: solar, wind, hydroelectric, and geothermal. I'll batch these research calls to efficiently gather information on all remaining categories. Result: results=[ActionStepResult(tool_id='call_0', tool_name='research_topic', tool_arguments={'topic': 'geothermal energy'}, tool_result="Research results for 'geothermal energy': Found 5 relevant sources with key insights.", success=True, error=None)] [3] Now that research on renewable energy, biomass, and geothermal energy has been completed, the next step is to create a structured outline for the article. This outline will organize the gathered research into coherent sections, ensuring comprehensive coverage of the topic while highlighting key insights from each energy type. The outline will serve as the foundation for writing individual sections. Result: results=[ActionStepResult(tool_id='call_0', tool_name='create_outline', tool_arguments={'title': 'Renewable Energy: Types, Benefits, and Future Prospects', 'research': 'Research includes general renewable energy overview (5 sources), biomass energy details (5 sources), and geothermal energy insights (5 sources). Key themes: sustainability, technological advancements, environmental impact, and global adoption trends.'}, tool_result="Outline for 'Renewable Energy: Types, Benefits, and Future Prosp... [18:37:36.795] [Think] (_cognitive_worker.py:332) Total: 1089 tokens (cumulative: 1947) [18:37:36.798] [Think] (_amphibious_automa.py:867) _PromptWorker: finish=False, step=The outline has been created successfully in Step 3. Now I need to write the article sections based on the outline and gathered research. I'll start by writing the introduction section, then continue with sections on different renewable energy types (solar, wind, hydroelectric, geothermal, biomass), benefits, and future prospects. I'll use the write_section tool to create each section systematically. [18:37:36.802] [Act] (_amphibious_automa.py:873) _PromptWorker: { "content": "The outline has been created successfully in Step 3. Now I need to write the article sections based on the outline and gathered research. I'll start by writing the introduction section, then continue with sections on different renewable energy types (solar, wind, hydroelectric, geothermal, biomass), benefits, and future prospects. I'll use the write_section tool to create each section systematically.", "result": { "results": [ { "tool_id": "call_0", "tool_name": "write_section", "tool_arguments": { "title": "Renewable Energy: Types, Benefits, and Future Prospects", "section": "Introduction", "notes": "Write an engaging introduction that defines renewable energy, explains its importance in addressing climate change, and previews the main types of renewable energy that will be covered in the article. Include key statistics about global renewable energy adoption and the urgency of transitioning from fossil fuels." }, "tool_result": "Written section 'Introduction' for 'Renewable Energy: Types, Benefits, and Future Prospects' (314 chars of notes used)", "success": true, "error": null }, { "tool_id": "call_1", "tool_name": "write_section", "tool_arguments": { "title": "Renewable Energy: Types, Benefits, and Future Prospects", "section": "Solar Energy", "notes": "Cover how solar energy works, current technology (photovoltaic cells, solar thermal), efficiency improvements, cost trends, and global adoption rates. Include information about both residential and commercial applications." }, "tool_result": "Written section 'Solar Energy' for 'Renewable Energy: Types, Benefits, and Future Prospects' (222 chars of notes used)", "success": true, "error": null }, { "tool_id": "call_2", "tool_name": "write_section", "tool_arguments": { "title": "Renewable Energy: Types, Benefits, and Future Prospects", "section": "Wind Energy", "notes": "Explain wind turbine technology, onshore vs offshore wind farms, capacity factors, environmental considerations, and major wind energy producing countries. Discuss recent technological advancements in turbine design." }, "tool_result": "Written section 'Wind Energy' for 'Renewable Energy: Types, Benefits, and Future Prospects' (216 chars of notes used)", "success": true, "error": null } ] }, "metadata": {}, "status": null } [18:37:36.802] [Observe] (_amphibious_automa.py:861) _PromptWorker: None [18:38:25.311] [Think] (_cognitive_worker.py:332) Message 1 (system, 347 tokens): Write the article based on the research gathered so far.Respond in JSON format. # Available Tools (with parameters): • research_topic: Search for information about a topic - topic (string) [required] • create_outline: Create an outline for an article - title (string) [required] - research (string) [required] • write_section: Write an article section based on outline and research - title (string) [required] - section (string) [required] - notes (string) [required] # Context Acquiring If the context contains progressively disclosed information (e.g. skills, history steps) and you want to inspect the details, use the **details** field to request them. The framework will expand these items in the next round. Batch all requests in a single output. When using this field, leave step_content and output empty. ## Field format: - **details**: [{field: "skills", index: 0}, ...] Available fields: **skills** (view a skill's full workflow), **cognitive_history** (view the full result of a previous step) # Output Fields - **step_content**: Your analysis and reasoning for this step - **finish**: Set True when the sub-task is fully complete (default: False) - **details**: Available fields: **skills**, **cognitive_history**. example: [{field: 'skills', index: 0}, ...] - **output**: Tool calls to execute: [{tool, tool_arguments: [{name: 'param', value: 'value'}]}] [18:38:25.311] [Think] (_cognitive_worker.py:332) Message 2 (user, 974 tokens): Based on the context below, decide your next action. Goal: Write the article using the gathered research Execution History: [Working Memory (0-4)] [0] Starting the research process on renewable energy. This is the first step, so I need to gather comprehensive information about the topic using the research_topic tool. This will provide the foundation for creating an outline and writing sections later. Result: results=[ActionStepResult(tool_id='call_0', tool_name='research_topic', tool_arguments={'topic': 'renewable energy'}, tool_result="Research results for 'renewable energy': Found 5 relevant sources with key insights.", success=True, error=None)] [1] The initial research on renewable energy was successful, finding 5 relevant sources. However, to gather comprehensive research material, I need to dive deeper into specific renewable energy types. I'll conduct additional research on the main categories of renewable energy: solar, wind, hydroelectric, geothermal, and biomass. This will provide detailed information for each major renewable energy source. Result: results=[ActionStepResult(tool_id='call_0', tool_name='research_topic', tool_arguments={'topic': 'biomass energy'}, tool_result="Research results for 'biomass energy': Found 5 relevant sources with key insights.", success=True, error=None)] [2] Based on the execution history, I've successfully completed initial research on 'renewable energy' (Step 0) and 'biomass energy' (Step 1). To gather comprehensive research material on renewable energy, I need to continue researching the other major renewable energy types mentioned in Step 1's reasoning: solar, wind, hydroelectric, and geothermal. I'll batch these research calls to efficiently gather information on all remaining categories. Result: results=[ActionStepResult(tool_id='call_0', tool_name='research_topic', tool_arguments={'topic': 'geothermal energy'}, tool_result="Research results for 'geothermal energy': Found 5 relevant sources with key insights.", success=True, error=None)] [3] Now that research on renewable energy, biomass, and geothermal energy has been completed, the next step is to create a structured outline for the article. This outline will organize the gathered research into coherent sections, ensuring comprehensive coverage of the topic while highlighting key insights from each energy type. The outline will serve as the foundation for writing individual sections. Result: results=[ActionStepResult(tool_id='call_0', tool_name='create_outline', tool_arguments={'title': 'Renewable Energy: Types, Benefits, and Future Prospects', 'research': 'Research includes general renewable energy overview (5 sources), biomass energy details (5 sources), and geothermal energy insights (5 sources). Key themes: sustainability, technological advancements, environmental impact, and global adoption trends.'}, tool_result="Outline for 'Renewable Energy: Types, Benefits, and Future Prosp... [4] The outline has been created successfully in Step 3. Now I need to write the article sections based on the outline and gathered research. I'll start by writing the introduction section, then continue with sections on different renewable energy types (solar, wind, hydroelectric, geothermal, biomass), benefits, and future prospects. I'll use the write_section tool to create each section systematically. Result: results=[ActionStepResult(tool_id='call_0', tool_name='write_section', tool_arguments={'title': 'Renewable Energy: Types, Benefits, and Future Prospects', 'section': 'Introduction', 'notes': 'Write an engaging introduction that defines renewable energy, explains its importance in addressing climate change, and previews the main types of renewable energy that will be covered in the article. Include key statistics about global renewable energy adoption and the urgency of transitioning from fossil ... [18:38:25.311] [Think] (_cognitive_worker.py:332) Total: 1321 tokens (cumulative: 3268) [18:38:25.315] [Think] (_amphibious_automa.py:867) _PromptWorker: finish=False, step=The introduction section has been completed. The next step is to write the section on Solar Energy, utilizing the general renewable energy research from Step 0 and integrating key insights about technology, adoption, and benefits. This ensures continuity in the article structure while leveraging available research data. [18:38:25.317] [Act] (_amphibious_automa.py:873) _PromptWorker: { "content": "The introduction section has been completed. The next step is to write the section on Solar Energy, utilizing the general renewable energy research from Step 0 and integrating key insights about technology, adoption, and benefits. This ensures continuity in the article structure while leveraging available research data.", "result": { "results": [ { "tool_id": "call_0", "tool_name": "write_section", "tool_arguments": { "title": "Renewable Energy: Types, Benefits, and Future Prospects", "section": "Solar Energy", "notes": "Cover photovoltaic technology, global adoption trends, cost reductions, and environmental impact. Reference general renewable energy research (Step 0) for statistics and contextualize solar energy's role in the transition from fossil fuels." }, "tool_result": "Written section 'Solar Energy' for 'Renewable Energy: Types, Benefits, and Future Prospects' (240 chars of notes used)", "success": true, "error": null } ] }, "metadata": {}, "status": null } [18:38:25.318] [Observe] (_amphibious_automa.py:861) _PromptWorker: None [18:38:34.677] [Think] (_cognitive_worker.py:332) Message 1 (system, 347 tokens): Write the article based on the research gathered so far.Respond in JSON format. # Available Tools (with parameters): • research_topic: Search for information about a topic - topic (string) [required] • create_outline: Create an outline for an article - title (string) [required] - research (string) [required] • write_section: Write an article section based on outline and research - title (string) [required] - section (string) [required] - notes (string) [required] # Context Acquiring If the context contains progressively disclosed information (e.g. skills, history steps) and you want to inspect the details, use the **details** field to request them. The framework will expand these items in the next round. Batch all requests in a single output. When using this field, leave step_content and output empty. ## Field format: - **details**: [{field: "skills", index: 0}, ...] Available fields: **skills** (view a skill's full workflow), **cognitive_history** (view the full result of a previous step) # Output Fields - **step_content**: Your analysis and reasoning for this step - **finish**: Set True when the sub-task is fully complete (default: False) - **details**: Available fields: **skills**, **cognitive_history**. example: [{field: 'skills', index: 0}, ...] - **output**: Tool calls to execute: [{tool, tool_arguments: [{name: 'param', value: 'value'}]}] [18:38:34.677] [Think] (_cognitive_worker.py:332) Message 2 (user, 1150 tokens): Based on the context below, decide your next action. Goal: Write the article using the gathered research Execution History: (Steps [0-0]: summary only, query details via details) [Short-term Memory (0-0), query details via 'details'] [0] Starting the research process on renewable energy. This is the first step, so I need to gather comprehensive information about the topic using the research_topic tool. This will provide the foundation for creating an outline and writing sections later. [Working Memory (1-5)] [1] The initial research on renewable energy was successful, finding 5 relevant sources. However, to gather comprehensive research material, I need to dive deeper into specific renewable energy types. I'll conduct additional research on the main categories of renewable energy: solar, wind, hydroelectric, geothermal, and biomass. This will provide detailed information for each major renewable energy source. Result: results=[ActionStepResult(tool_id='call_0', tool_name='research_topic', tool_arguments={'topic': 'biomass energy'}, tool_result="Research results for 'biomass energy': Found 5 relevant sources with key insights.", success=True, error=None)] [2] Based on the execution history, I've successfully completed initial research on 'renewable energy' (Step 0) and 'biomass energy' (Step 1). To gather comprehensive research material on renewable energy, I need to continue researching the other major renewable energy types mentioned in Step 1's reasoning: solar, wind, hydroelectric, and geothermal. I'll batch these research calls to efficiently gather information on all remaining categories. Result: results=[ActionStepResult(tool_id='call_0', tool_name='research_topic', tool_arguments={'topic': 'geothermal energy'}, tool_result="Research results for 'geothermal energy': Found 5 relevant sources with key insights.", success=True, error=None)] [3] Now that research on renewable energy, biomass, and geothermal energy has been completed, the next step is to create a structured outline for the article. This outline will organize the gathered research into coherent sections, ensuring comprehensive coverage of the topic while highlighting key insights from each energy type. The outline will serve as the foundation for writing individual sections. Result: results=[ActionStepResult(tool_id='call_0', tool_name='create_outline', tool_arguments={'title': 'Renewable Energy: Types, Benefits, and Future Prospects', 'research': 'Research includes general renewable energy overview (5 sources), biomass energy details (5 sources), and geothermal energy insights (5 sources). Key themes: sustainability, technological advancements, environmental impact, and global adoption trends.'}, tool_result="Outline for 'Renewable Energy: Types, Benefits, and Future Prosp... [4] The outline has been created successfully in Step 3. Now I need to write the article sections based on the outline and gathered research. I'll start by writing the introduction section, then continue with sections on different renewable energy types (solar, wind, hydroelectric, geothermal, biomass), benefits, and future prospects. I'll use the write_section tool to create each section systematically. Result: results=[ActionStepResult(tool_id='call_0', tool_name='write_section', tool_arguments={'title': 'Renewable Energy: Types, Benefits, and Future Prospects', 'section': 'Introduction', 'notes': 'Write an engaging introduction that defines renewable energy, explains its importance in addressing climate change, and previews the main types of renewable energy that will be covered in the article. Include key statistics about global renewable energy adoption and the urgency of transitioning from fossil ... [5] The introduction section has been completed. The next step is to write the section on Solar Energy, utilizing the general renewable energy research from Step 0 and integrating key insights about technology, adoption, and benefits. This ensures continuity in the article structure while leveraging available research data. Result: results=[ActionStepResult(tool_id='call_0', tool_name='write_section', tool_arguments={'title': 'Renewable Energy: Types, Benefits, and Future Prospects', 'section': 'Solar Energy', 'notes': "Cover photovoltaic technology, global adoption trends, cost reductions, and environmental impact. Reference general renewable energy research (Step 0) for statistics and contextualize solar energy's role in the transition from fossil fuels."}, tool_result="Written section 'Solar Energy' for 'Renewable Energ... [18:38:34.677] [Think] (_cognitive_worker.py:332) Total: 1497 tokens (cumulative: 4765) [18:38:34.681] [Think] (_amphibious_automa.py:867) _PromptWorker: finish=False, step=Based on the execution history, I've successfully completed the Introduction (Step 4) and Solar Energy (Step 5) sections. Following the article outline structure, I need to continue writing the remaining sections systematically. The next logical section is Wind Energy, which is one of the major renewable energy types that should be covered. I'll use the write_section tool to create this section, incorporating relevant research data and maintaining consistency with the article's tone and structure. [18:38:34.684] [Act] (_amphibious_automa.py:873) _PromptWorker: { "content": "Based on the execution history, I've successfully completed the Introduction (Step 4) and Solar Energy (Step 5) sections. Following the article outline structure, I need to continue writing the remaining sections systematically. The next logical section is Wind Energy, which is one of the major renewable energy types that should be covered. I'll use the write_section tool to create this section, incorporating relevant research data and maintaining consistency with the article's tone and structure.", "result": { "results": [ { "tool_id": "call_0", "tool_name": "write_section", "tool_arguments": { "title": "Renewable Energy: Types, Benefits, and Future Prospects", "section": "Wind Energy", "notes": "Cover wind turbine technology, onshore and offshore wind farms, global capacity growth, cost efficiency improvements, and environmental considerations. Reference general renewable energy research for statistics and contextualize wind energy's contribution to the global energy transition." }, "tool_result": "Written section 'Wind Energy' for 'Renewable Energy: Types, Benefits, and Future Prospects' (288 chars of notes used)", "success": true, "error": null } ] }, "metadata": {}, "status": null } [18:38:34.684] [Observe] (_amphibious_automa.py:861) _PromptWorker: None [18:38:45.447] [Think] (_cognitive_worker.py:332) Message 1 (system, 347 tokens): Write the article based on the research gathered so far.Respond in JSON format. # Available Tools (with parameters): • research_topic: Search for information about a topic - topic (string) [required] • create_outline: Create an outline for an article - title (string) [required] - research (string) [required] • write_section: Write an article section based on outline and research - title (string) [required] - section (string) [required] - notes (string) [required] # Context Acquiring If the context contains progressively disclosed information (e.g. skills, history steps) and you want to inspect the details, use the **details** field to request them. The framework will expand these items in the next round. Batch all requests in a single output. When using this field, leave step_content and output empty. ## Field format: - **details**: [{field: "skills", index: 0}, ...] Available fields: **skills** (view a skill's full workflow), **cognitive_history** (view the full result of a previous step) # Output Fields - **step_content**: Your analysis and reasoning for this step - **finish**: Set True when the sub-task is fully complete (default: False) - **details**: Available fields: **skills**, **cognitive_history**. example: [{field: 'skills', index: 0}, ...] - **output**: Tool calls to execute: [{tool, tool_arguments: [{name: 'param', value: 'value'}]}] [18:38:45.447] [Think] (_cognitive_worker.py:332) Message 2 (user, 1343 tokens): Based on the context below, decide your next action. Goal: Write the article using the gathered research Execution History: (Steps [0-1]: summary only, query details via details) [Short-term Memory (0-1), query details via 'details'] [0] Starting the research process on renewable energy. This is the first step, so I need to gather comprehensive information about the topic using the research_topic tool. This will provide the foundation for creating an outline and writing sections later. [1] The initial research on renewable energy was successful, finding 5 relevant sources. However, to gather comprehensive research material, I need to dive deeper into specific renewable energy types. I'll conduct additional research on the main categories of renewable energy: solar, wind, hydroelectric, geothermal, and biomass. This will provide detailed information for each major renewable energy source. [Working Memory (2-6)] [2] Based on the execution history, I've successfully completed initial research on 'renewable energy' (Step 0) and 'biomass energy' (Step 1). To gather comprehensive research material on renewable energy, I need to continue researching the other major renewable energy types mentioned in Step 1's reasoning: solar, wind, hydroelectric, and geothermal. I'll batch these research calls to efficiently gather information on all remaining categories. Result: results=[ActionStepResult(tool_id='call_0', tool_name='research_topic', tool_arguments={'topic': 'geothermal energy'}, tool_result="Research results for 'geothermal energy': Found 5 relevant sources with key insights.", success=True, error=None)] [3] Now that research on renewable energy, biomass, and geothermal energy has been completed, the next step is to create a structured outline for the article. This outline will organize the gathered research into coherent sections, ensuring comprehensive coverage of the topic while highlighting key insights from each energy type. The outline will serve as the foundation for writing individual sections. Result: results=[ActionStepResult(tool_id='call_0', tool_name='create_outline', tool_arguments={'title': 'Renewable Energy: Types, Benefits, and Future Prospects', 'research': 'Research includes general renewable energy overview (5 sources), biomass energy details (5 sources), and geothermal energy insights (5 sources). Key themes: sustainability, technological advancements, environmental impact, and global adoption trends.'}, tool_result="Outline for 'Renewable Energy: Types, Benefits, and Future Prosp... [4] The outline has been created successfully in Step 3. Now I need to write the article sections based on the outline and gathered research. I'll start by writing the introduction section, then continue with sections on different renewable energy types (solar, wind, hydroelectric, geothermal, biomass), benefits, and future prospects. I'll use the write_section tool to create each section systematically. Result: results=[ActionStepResult(tool_id='call_0', tool_name='write_section', tool_arguments={'title': 'Renewable Energy: Types, Benefits, and Future Prospects', 'section': 'Introduction', 'notes': 'Write an engaging introduction that defines renewable energy, explains its importance in addressing climate change, and previews the main types of renewable energy that will be covered in the article. Include key statistics about global renewable energy adoption and the urgency of transitioning from fossil ... [5] The introduction section has been completed. The next step is to write the section on Solar Energy, utilizing the general renewable energy research from Step 0 and integrating key insights about technology, adoption, and benefits. This ensures continuity in the article structure while leveraging available research data. Result: results=[ActionStepResult(tool_id='call_0', tool_name='write_section', tool_arguments={'title': 'Renewable Energy: Types, Benefits, and Future Prospects', 'section': 'Solar Energy', 'notes': "Cover photovoltaic technology, global adoption trends, cost reductions, and environmental impact. Reference general renewable energy research (Step 0) for statistics and contextualize solar energy's role in the transition from fossil fuels."}, tool_result="Written section 'Solar Energy' for 'Renewable Energ... [6] Based on the execution history, I've successfully completed the Introduction (Step 4) and Solar Energy (Step 5) sections. Following the article outline structure, I need to continue writing the remaining sections systematically. The next logical section is Wind Energy, which is one of the major renewable energy types that should be covered. I'll use the write_section tool to create this section, incorporating relevant research data and maintaining consistency with the article's tone and structure. Result: results=[ActionStepResult(tool_id='call_0', tool_name='write_section', tool_arguments={'title': 'Renewable Energy: Types, Benefits, and Future Prospects', 'section': 'Wind Energy', 'notes': "Cover wind turbine technology, onshore and offshore wind farms, global capacity growth, cost efficiency improvements, and environmental considerations. Reference general renewable energy research for statistics and contextualize wind energy's contribution to the global energy transition."}, tool_result="Writ... [18:38:45.447] [Think] (_cognitive_worker.py:332) Total: 1690 tokens (cumulative: 6455) [18:38:45.449] [Think] (_amphibious_automa.py:867) _PromptWorker: finish=False, step=Based on the execution history, I've successfully completed the Introduction (Step 4), Solar Energy (Step 5), and Wind Energy (Step 6) sections. Following the article outline structure, I need to continue writing the remaining sections systematically. The next logical section is Hydroelectric Energy, which is one of the major renewable energy types that should be covered. I'll use the write_section tool to create this section, incorporating relevant research data and maintaining consistency with the article's tone and structure. [18:38:45.452] [Act] (_amphibious_automa.py:873) _PromptWorker: { "content": "Based on the execution history, I've successfully completed the Introduction (Step 4), Solar Energy (Step 5), and Wind Energy (Step 6) sections. Following the article outline structure, I need to continue writing the remaining sections systematically. The next logical section is Hydroelectric Energy, which is one of the major renewable energy types that should be covered. I'll use the write_section tool to create this section, incorporating relevant research data and maintaining consistency with the article's tone and structure.", "result": { "results": [ { "tool_id": "call_0", "tool_name": "write_section", "tool_arguments": { "title": "Renewable Energy: Types, Benefits, and Future Prospects", "section": "Hydroelectric Energy", "notes": "Cover hydroelectric power generation methods, dam-based and run-of-river systems, global capacity and leading countries, environmental considerations including ecosystem impact, and the role of hydroelectric energy in providing stable baseload power. Reference general renewable energy research for statistics and contextualize hydroelectric energy's contribution to the global energy mix." }, "tool_result": "Written section 'Hydroelectric Energy' for 'Renewable Energy: Types, Benefits, and Future Prospects' (389 chars of notes used)", "success": true, "error": null } ] }, "metadata": {}, "status": null } ================================================== ContentCreator-560f7dc9 | Completed Tokens: 8032 | Time: 130.48s ================================================== {'goal': 'Goal: Write an article about the future of renewable energy', 'tools': 'Available Tools:\n • research_topic: Search for information about a topic\n • create_outline: Create an outline for an article\n • write_section: Write an article section based on outline and research', 'cognitive_history': 'Execution History:\n (Steps [0-2]: summary only, query details via details)\n [Short-term Memory (0-2), query details via \'details\']\n [0] Starting the research process on renewable energy. This is the first step, so I need to gather comprehensive information about the topic using the research_topic tool. This will provide the foundation for creating an outline and writing sections later.\n [1] The initial research on renewable energy was successful, finding 5 relevant sources. However, to gather comprehensive research material, I need to dive deeper into specific renewable energy types. I\'ll conduct additional research on the main categories of renewable energy: solar, wind, hydroelectric, geothermal, and biomass. This will provide detailed information for each major renewable energy source.\n [2] Based on the execution history, I\'ve successfully completed initial research on \'renewable energy\' (Step 0) and \'biomass energy\' (Step 1). To gather comprehensive research material on renewable energy, I need to continue researching the other major renewable energy types mentioned in Step 1\'s reasoning: solar, wind, hydroelectric, and geothermal. I\'ll batch these research calls to efficiently gather information on all remaining categories.\n [Working Memory (3-7)]\n [3] Now that research on renewable energy, biomass, and geothermal energy has been completed, the next step is to create a structured outline for the article. This outline will organize the gathered research into coherent sections, ensuring comprehensive coverage of the topic while highlighting key insights from each energy type. The outline will serve as the foundation for writing individual sections.\n Result: results=[ActionStepResult(tool_id=\'call_0\', tool_name=\'create_outline\', tool_arguments={\'title\': \'Renewable Energy: Types, Benefits, and Future Prospects\', \'research\': \'Research includes general renewable energy overview (5 sources), biomass energy details (5 sources), and geothermal energy insights (5 sources). Key themes: sustainability, technological advancements, environmental impact, and global adoption trends.\'}, tool_result="Outline for \'Renewable Energy: Types, Benefits, and Future Prosp...\n [4] The outline has been created successfully in Step 3. Now I need to write the article sections based on the outline and gathered research. I\'ll start by writing the introduction section, then continue with sections on different renewable energy types (solar, wind, hydroelectric, geothermal, biomass), benefits, and future prospects. I\'ll use the write_section tool to create each section systematically.\n Result: results=[ActionStepResult(tool_id=\'call_0\', tool_name=\'write_section\', tool_arguments={\'title\': \'Renewable Energy: Types, Benefits, and Future Prospects\', \'section\': \'Introduction\', \'notes\': \'Write an engaging introduction that defines renewable energy, explains its importance in addressing climate change, and previews the main types of renewable energy that will be covered in the article. Include key statistics about global renewable energy adoption and the urgency of transitioning from fossil ...\n [5] The introduction section has been completed. The next step is to write the section on Solar Energy, utilizing the general renewable energy research from Step 0 and integrating key insights about technology, adoption, and benefits. This ensures continuity in the article structure while leveraging available research data.\n Result: results=[ActionStepResult(tool_id=\'call_0\', tool_name=\'write_section\', tool_arguments={\'title\': \'Renewable Energy: Types, Benefits, and Future Prospects\', \'section\': \'Solar Energy\', \'notes\': "Cover photovoltaic technology, global adoption trends, cost reductions, and environmental impact. Reference general renewable energy research (Step 0) for statistics and contextualize solar energy\'s role in the transition from fossil fuels."}, tool_result="Written section \'Solar Energy\' for \'Renewable Energ...\n [6] Based on the execution history, I\'ve successfully completed the Introduction (Step 4) and Solar Energy (Step 5) sections. Following the article outline structure, I need to continue writing the remaining sections systematically. The next logical section is Wind Energy, which is one of the major renewable energy types that should be covered. I\'ll use the write_section tool to create this section, incorporating relevant research data and maintaining consistency with the article\'s tone and structure.\n Result: results=[ActionStepResult(tool_id=\'call_0\', tool_name=\'write_section\', tool_arguments={\'title\': \'Renewable Energy: Types, Benefits, and Future Prospects\', \'section\': \'Wind Energy\', \'notes\': "Cover wind turbine technology, onshore and offshore wind farms, global capacity growth, cost efficiency improvements, and environmental considerations. Reference general renewable energy research for statistics and contextualize wind energy\'s contribution to the global energy transition."}, tool_result="Writ...\n [7] Based on the execution history, I\'ve successfully completed the Introduction (Step 4), Solar Energy (Step 5), and Wind Energy (Step 6) sections. Following the article outline structure, I need to continue writing the remaining sections systematically. The next logical section is Hydroelectric Energy, which is one of the major renewable energy types that should be covered. I\'ll use the write_section tool to create this section, incorporating relevant research data and maintaining consistency with the article\'s tone and structure.\n Result: results=[ActionStepResult(tool_id=\'call_0\', tool_name=\'write_section\', tool_arguments={\'title\': \'Renewable Energy: Types, Benefits, and Future Prospects\', \'section\': \'Hydroelectric Energy\', \'notes\': "Cover hydroelectric power generation methods, dam-based and run-of-river systems, global capacity and leading countries, environmental considerations including ecosystem impact, and the role of hydroelectric energy in providing stable baseload power. Reference general renewable energy research for s...'}
In the verbose output above, notice how the LLM's goal changes between phases:
- During the first snapshot, it sees "Gather research material on renewable energy" and focuses on calling
research_topic - During the second snapshot, it sees "Write the article using the gathered research" and focuses on calling
write_section
Each snapshot scopes the LLM's focus to one sub-task. The agent's overall goal ("Write an article about the future of renewable energy") is temporarily replaced inside each block, then restored on exit.
What have we learnt?¶
In this tutorial, we explored Phase Annotation — structured context scoping for agent execution phases:
self.snapshot(goal="...", **fields)is the core mechanism. It creates a scoped context where think units run, then automatically restores the original state on exit.- On enter: saves original fields, applies overrides, clears
LayeredExposurerevealed state - On exit: restores all fields and revealed state
- On enter: saves original fields, applies overrides, clears
- Snapshot is ideal for sub-goal scoping, interruption handling, and context isolation between phases.