Mini-project: Guarded autonomous repo maintainer
Combine Rules + Hooks + Autonomy + Execution caps into one safe worker
In this capstone for Hooks and autonomy, you build a repo-maintenance agent governed by AGENTS.md rules, audited by HooksConfig on every tool call, constrained by AutonomyConfig, and capped by ExecutionConfig.
Example
import tempfile
from pathlib import Path
from praisonai import Agent, HooksConfig, RulesConfig, AutonomyConfig, AutonomyLevel, ExecutionConfig
audit = []
def scan_stale_todos() -> str:
"""Return stale TODO items in repo."""
return 'Found 2 stale TODOs in src/billing.py'
with tempfile.TemporaryDirectory() as tmp:
rules_path = Path(tmp) / 'AGENTS.md'
rules_path.write_text('# Rules\n- Propose PRs only; never push to main.\n')
maintainer = Agent(
name='RepoMaintainer',
instructions='Call scan_stale_todos and summarize a 1-sentence PR proposal.',
tools=[scan_stale_todos],
rules=RulesConfig(files=[str(rules_path)], char_budget=2000, workspace_path=tmp),
hooks=HooksConfig(on_tool_call=lambda ev: audit.append(ev.tool_name)),
autonomy=AutonomyConfig(enabled=True, level=AutonomyLevel.SUGGEST, max_iterations=3, doom_loop_threshold=2, max_budget_usd=0.25),
execution=ExecutionConfig(max_iter=3, max_budget=0.25, context_compaction=True),
output='silent',
)
print('Report:', maintainer.start('Run weekly repo hygiene check'))
print('Audit :', audit)Example explained
- RulesConfig + HooksConfig — Applies workspace standards and records every tool invocation automatically.
- AutonomyConfig + ExecutionConfig — Double-bounds iterations, doom loops, and dollar budget at $0.25.
Verify your 4-layer safety checklist
Before scheduling any autonomous agent with Heartbeat, verify all four layers are active: (1) RulesConfig loaded, (2) HooksConfig audit trail writing to logs, (3) AutonomyConfig doom_loop_threshold set, and (4) ExecutionConfig max_budget capped.
Reference: documentation