The converter translates natural language patterns into specific SDK patterns. When writing or reviewing generated code, understand these five core patterns:
- Sequential Stages with Context: Uses
agent.session() to maintain continuity between steps. - Conditional Logic: Uses typed results (e.g.,
bool) to drive if/else control flow. - Loops/Iterations: Uses Python loops over collections returned by the agent.
- Data Dependencies: Uses
dataclasses and type hints to pass structured data between steps. - Function Calling: Uses
agent.run() to allow the agent to execute local Python functions.
# Example of Sequential Stages with Context
with agent.session() as session:
session("Step 1: Create the base structure")
session("Step 2: Add features")
# Example of Conditional Logic
result = agent("Check if the file exists", bool)
if result:
agent("Process the existing file")
# Example of Data Dependencies
@dataclass
class FileInfo:
path: str
size: int
files = agent("Analyze all config files", list[FileInfo])
for file in files:
if file.size > 1000:
agent(f"Optimize {file.path}")
# Example of Function Calling
def run_tests(test_file: str) -> dict:
return {"passed": 10, "failed": 0}
result = agent.run(
"Run all tests",
return_type=dict,
functions=[run_tests]
)