$npx -y skills add SamarthaKV29/antigravity-god-mode --skill autonomous-agent-patternsDesign patterns for building autonomous coding agents. Covers tool integration, permission systems, browser automation, and human-in-the-loop workflows. Use when building AI agents, designing tool APIs, implementing permission systems, or creating autonomous coding assistants.
| 1 | # 🕹️ Autonomous Agent Patterns |
| 2 | |
| 3 | > Design patterns for building autonomous coding agents, inspired by [Cline](https://github.com/cline/cline) and [OpenAI Codex](https://github.com/openai/codex). |
| 4 | |
| 5 | ## When to Use This Skill |
| 6 | |
| 7 | Use this skill when: |
| 8 | |
| 9 | - Building autonomous AI agents |
| 10 | - Designing tool/function calling APIs |
| 11 | - Implementing permission and approval systems |
| 12 | - Creating browser automation for agents |
| 13 | - Designing human-in-the-loop workflows |
| 14 | |
| 15 | --- |
| 16 | |
| 17 | ## 1. Core Agent Architecture |
| 18 | |
| 19 | ### 1.1 Agent Loop |
| 20 | |
| 21 | ``` |
| 22 | ┌─────────────────────────────────────────────────────────────┐ |
| 23 | │ AGENT LOOP │ |
| 24 | │ │ |
| 25 | │ ┌──────────┐ ┌──────────┐ ┌──────────┐ │ |
| 26 | │ │ Think │───▶│ Decide │───▶│ Act │ │ |
| 27 | │ │ (Reason) │ │ (Plan) │ │ (Execute)│ │ |
| 28 | │ └──────────┘ └──────────┘ └──────────┘ │ |
| 29 | │ ▲ │ │ |
| 30 | │ │ ┌──────────┐ │ │ |
| 31 | │ └─────────│ Observe │◀─────────┘ │ |
| 32 | │ │ (Result) │ │ |
| 33 | │ └──────────┘ │ |
| 34 | └─────────────────────────────────────────────────────────────┘ |
| 35 | ``` |
| 36 | |
| 37 | ```python |
| 38 | class AgentLoop: |
| 39 | def __init__(self, llm, tools, max_iterations=50): |
| 40 | self.llm = llm |
| 41 | self.tools = {t.name: t for t in tools} |
| 42 | self.max_iterations = max_iterations |
| 43 | self.history = [] |
| 44 | |
| 45 | def run(self, task: str) -> str: |
| 46 | self.history.append({"role": "user", "content": task}) |
| 47 | |
| 48 | for i in range(self.max_iterations): |
| 49 | # Think: Get LLM response with tool options |
| 50 | response = self.llm.chat( |
| 51 | messages=self.history, |
| 52 | tools=self._format_tools(), |
| 53 | tool_choice="auto" |
| 54 | ) |
| 55 | |
| 56 | # Decide: Check if agent wants to use a tool |
| 57 | if response.tool_calls: |
| 58 | for tool_call in response.tool_calls: |
| 59 | # Act: Execute the tool |
| 60 | result = self._execute_tool(tool_call) |
| 61 | |
| 62 | # Observe: Add result to history |
| 63 | self.history.append({ |
| 64 | "role": "tool", |
| 65 | "tool_call_id": tool_call.id, |
| 66 | "content": str(result) |
| 67 | }) |
| 68 | else: |
| 69 | # No more tool calls = task complete |
| 70 | return response.content |
| 71 | |
| 72 | return "Max iterations reached" |
| 73 | |
| 74 | def _execute_tool(self, tool_call) -> Any: |
| 75 | tool = self.tools[tool_call.name] |
| 76 | args = json.loads(tool_call.arguments) |
| 77 | return tool.execute(**args) |
| 78 | ``` |
| 79 | |
| 80 | ### 1.2 Multi-Model Architecture |
| 81 | |
| 82 | ```python |
| 83 | class MultiModelAgent: |
| 84 | """ |
| 85 | Use different models for different purposes: |
| 86 | - Fast model for planning |
| 87 | - Powerful model for complex reasoning |
| 88 | - Specialized model for code generation |
| 89 | """ |
| 90 | |
| 91 | def __init__(self): |
| 92 | self.models = { |
| 93 | "fast": "gpt-3.5-turbo", # Quick decisions |
| 94 | "smart": "gpt-4-turbo", # Complex reasoning |
| 95 | "code": "claude-3-sonnet", # Code generation |
| 96 | } |
| 97 | |
| 98 | def select_model(self, task_type: str) -> str: |
| 99 | if task_type == "planning": |
| 100 | return self.models["fast"] |
| 101 | elif task_type == "analysis": |
| 102 | return self.models["smart"] |
| 103 | elif task_type == "code": |
| 104 | return self.models["code"] |
| 105 | return self.models["smart"] |
| 106 | ``` |
| 107 | |
| 108 | --- |
| 109 | |
| 110 | ## 2. Tool Design Patterns |
| 111 | |
| 112 | ### 2.1 Tool Schema |
| 113 | |
| 114 | ```python |
| 115 | class Tool: |
| 116 | """Base class for agent tools""" |
| 117 | |
| 118 | @property |
| 119 | def schema(self) -> dict: |
| 120 | """JSON Schema for the tool""" |
| 121 | return { |
| 122 | "name": self.name, |
| 123 | "description": self.description, |
| 124 | "parameters": { |
| 125 | "type": "object", |
| 126 | "properties": self._get_parameters(), |
| 127 | "required": self._get_required() |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | def execute(self, **kwargs) -> ToolResult: |
| 132 | """Execute the tool and return result""" |
| 133 | raise NotImplementedError |
| 134 | |
| 135 | class ReadFileTool(Tool): |
| 136 | name = "read_file" |
| 137 | description = "Read the contents of a file from the filesystem" |
| 138 | |
| 139 | def _get_parameters(self): |
| 140 | return { |
| 141 | "path": { |
| 142 | "type": "string", |
| 143 | "description": "Absolute path to the file" |
| 144 | }, |
| 145 | "start_line": { |
| 146 | "type": "integer", |
| 147 | "description": "Line to start reading from (1-indexed)" |
| 148 | }, |
| 149 | "end_lin |