Observation-Thought-Action Cycle
The OTA cycle is the atomic unit of agent execution.
Task
Implement OTACycle that:
- Takes an observation and runs it through think and act functions.
- Records each step as a
Stepdataclass. - Returns formatted context of the last N steps for the next iteration.
Constraints
think_fn(observation: str) -> stract_fn(thought: str) -> str- Context format:
Obs: ... | Thought: ... | Action: ...per step.
Examples
Example 1:
Input:
cycle = OTACycle()
step = cycle.process('User asked for 2+2', lambda o: 'I should add', lambda t: 'call_add(2,2)')
step.thoughtOutput:
'I should add'Explanation: Think function transforms observation into thought.
Starter Code
from dataclasses import dataclass, field
from typing import List, Optional
@dataclass
class Step:
observation: str
thought: str
action: str
result: Optional[str] = None
class OTACycle:
def __init__(self):
self.steps: List[Step] = []
def process(self, observation: str, think_fn, act_fn) -> Step:
# TODO: Run one OTA cycle and record step
pass
def get_context(self, last_n: int = 3) -> str:
# TODO: Return formatted string of last N steps
pass
Python3
ReadyLines: 1Characters: 0
Ready