[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6H8V6AXF48AC666J6A1CTM8":3,"skill-same:01M6H8V6AXF48AC666J6A1CTM8":77},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":23,"publishedAt":43,"linkOnly":44,"markdownContent":45,"markdownBody":46,"frontMatter":47,"refName":55,"commitSha":56,"skillDirectory":57,"forksCount":14,"repositoryHtmlUrl":58,"repositoryHomepageUrl":6,"ownerHtmlUrl":59,"ownerBlogUrl":60,"ownerDescription":61,"updatedAt":62,"install":63,"resources":76},"01M6H8V6AXF48AC666J6A1CTM8","agentic-ai",null,"Expert guidance on agentic AI systems, autonomous agents, and AI orchestration. Use for:  building agentic AI systems, tool orchestration, memory systems, planning and reasoning,  multi-step workflows, feedback loops, evaluation frameworks, ReAct patterns, and building  sophisticated AI pipelines.","NeuralBlitz\u002FMito","NeuralBlitz","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F79354388?v=4","01M6H8T2TFH477HRS0KTSTKR2E","David Riggs","01M6H8T2YQQDXPYM092P670Z21",0,"MIT","https:\u002F\u002Fgithub.com\u002FNeuralBlitz\u002FMito\u002Fblob\u002Fmain\u002F.opencode\u002Fskills\u002Fagentic-ai\u002FSKILL.md",[18],{"categoryNo":19,"categoryName":20,"taxonomyType":21,"taxonomyTypeDesc":22},"01JBSEEDCAT000000000000009","前端开发","SCENARIO","使用场景",[24,25,26,27,28,29,30,31,32,33,34,35,36,5,37,38,39,40,41,42],"agentic ai","agentic","for","autonomous-agents","loops","intelligence","frameworks","patterns","expert","opencode","autonomous","sophisticated","feedback","Evaluation","planning","react","workflows","orchestration","memory","2026-11-10 10:12:30",false,"---\nname: agentic-ai\ndescription: >\n  Expert guidance on agentic AI systems, autonomous agents, and AI orchestration. Use for: \n  building agentic AI systems, tool orchestration, memory systems, planning and reasoning, \n  multi-step workflows, feedback loops, evaluation frameworks, ReAct patterns, and building \n  sophisticated AI pipelines.\nlicense: MIT\ncompatibility: opencode\nmetadata:\n  audience: ml-engineers, developers\n  category: artificial-intelligence\n  tags: [agentic-ai, autonomous-agents, ai-agents, llm-agents]\n---\n\n# Agentic AI — Implementation Guide\n\nCovers: **Agent Architectures · Tool Use · Memory Systems · Planning · Evaluation · Multi-Agent Systems**\n\n-----\n\n## Understanding Agentic AI\n\n### What Makes an AI \"Agentic\"?\n\nAn agentic AI system differs from traditional AI assistants in several fundamental ways. While a standard language model responds to each prompt independently, an agentic system maintains state across interactions, takes autonomous actions to achieve goals, and can plan multi-step sequences of operations.\n\nThe key characteristics that define agentic AI include: autonomy in decision-making without requiring constant human guidance, the ability to plan and execute multi-step workflows, the capacity to use external tools and APIs to interact with the world, memory systems that preserve context across interactions, and feedback mechanisms that enable learning and adaptation.\n\n**Agentic systems can be categorized by their complexity:**\n\nSimple reflex agents respond to stimuli based on predetermined rules. Goal-based agents work toward specific objectives using planning algorithms. Utility-based agents maximize expected utility through optimization. Learning agents improve performance through experience. Multi-agent systems involve multiple AI agents collaborating or competing.\n\n**Common Agent Architectures:**\n\n- **ReAct (Reason + Act)** — Combines reasoning traces with action execution\n- **Reflexion** — Adds verbal reinforcement learning for self-reflection\n- **Tool Use Agents** — Integrate external tools and APIs into reasoning\n- **Plan-and-Execute** — Separates planning from execution phases\n- **Multi-Agent** — Multiple specialized agents working together\n\n### When to Use Agentic Systems\n\nAgentic systems excel in scenarios requiring complex multi-step reasoning, dynamic tool orchestration, persistent context across sessions, autonomous decision-making, iterative refinement, or coordination of multiple specialized components. They are particularly valuable for building AI assistants that can take actions rather than just generating text.\n\nTraditional completion-based AI remains superior for simple question-answering, content generation, summarization, and single-turn interactions. The complexity of agentic systems is justified when the task genuinely requires persistent state, tool use, or multi-step execution.\n\n-----\n\n## Agent Architecture Design\n\n### Core Agent Loop\n\n```python\nfrom dataclasses import dataclass, field\nfrom typing import List, Dict, Any, Optional, Callable\nfrom enum import Enum\nfrom datetime import datetime\n\nclass AgentState(Enum):\n    IDLE = \"idle\"\n    REASONING = \"reasoning\"\n    ACTING = \"acting\"\n    OBSERVING = \"observing\"\n    FINISHED = \"finished\"\n    ERROR = \"error\"\n\n@dataclass\nclass Thought:\n    \"\"\"A single thought in the agent's reasoning chain\"\"\"\n    content: str\n    timestamp: datetime = field(default_factory=datetime.now)\n    action: Optional[str] = None\n    observation: Optional[str] = None\n\n@dataclass\nclass AgentConfig:\n    \"\"\"Configuration for agent behavior\"\"\"\n    model: str = \"claude-sonnet-4-5-20251120\"\n    max_iterations: int = 100\n    max_tokens_per_iteration: int = 4096\n    temperature: float = 0.7\n    tools: List[Any] = field(default_factory=list)\n    memory_system: Optional['MemorySystem'] = None\n    planning_enabled: bool = True\n    reflection_enabled: bool = True\n\nclass BaseAgent:\n    \"\"\"Core agent implementation\"\"\"\n    \n    def __init__(self, config: AgentConfig, llm_client):\n        self.config = config\n        self.llm = llm_client\n        self.state = AgentState.IDLE\n        self.thought_history: List[Thought] = []\n        self.tools = {tool.name: tool for tool in config.tools}\n    \n    async def run(self, task: str) -> Dict[str, Any]:\n        \"\"\"Main agent loop\"\"\"\n        self.task = task\n        self.thought_history = []\n        \n        for iteration in range(self.config.max_iterations):\n            # Think phase\n            thought = await self.think(task)\n            self.thought_history.append(thought)\n            \n            # Act phase\n            if thought.action:\n                result = await self.act(thought.action)\n                thought.observation = result\n                \n                # Check if task is complete\n                if self.is_complete(result):\n                    return self.format_result()\n            else:\n                # No action needed, provide final response\n                return {\"status\": \"completed\", \"response\": thought.content}\n        \n        return {\"status\": \"max_iterations\", \"thoughts\": self.thought_history}\n    \n    async def think(self, task: str) -> Thought:\n        \"\"\"Reason about the current state and determine next action\"\"\"\n        self.state = AgentState.REASONING\n        \n        # Build context from history and memory\n        context = self.build_context()\n        \n        # Get LLM response with action\n        response = await self.llm.chat([\n            {\"role\": \"system\", \"content\": self.get_system_prompt()},\n            {\"role\": \"user\", \"content\": f\"Task: {task}\\n\\n{context}\"}\n        ])\n        \n        return Thought(content=response.content, action=response.tool_use)\n    \n    async def act(self, action: str) -> str:\n        \"\"\"Execute the determined action\"\"\"\n        self.state = AgentState.ACTING\n        \n        if action in self.tools:\n            return await self.tools[action].execute()\n        else:\n            return action  # Plain text response\n    \n    def build_context(self) -> str:\n        \"\"\"Build context from thought history and memory\"\"\"\n        history = \"\\n\".join([\n            f\"- {t.content}\" + (f\" -> {t.observation}\" if t.observation else \"\")\n            for t in self.thought_history[-5:]\n        ])\n        \n        memory = \"\"\n        if self.config.memory_system:\n            memory = f\"\\nRelevant memory:\\n{self.config.memory_system.retrieve(self.task)}\"\n        \n        return f\"History:\\n{history}{memory}\"\n    \n    def is_complete(self, result: str) -> bool:\n        \"\"\"Determine if task is complete\"\"\"\n        completion_indicators = [\n            \"task complete\",\n            \"finished\",\n            \"successfully\",\n            \"delivered\"\n        ]\n        return any(indicator in result.lower() for indicator in completion_indicators)\n    \n    def format_result(self) -> Dict[str, Any]:\n        \"\"\"Format the final result\"\"\"\n        return {\n            \"status\": \"completed\",\n            \"thoughts\": [t.content for t in self.thought_history],\n            \"actions\": [t.action for t in self.thought_history if t.action],\n            \"observations\": [t.observation for t in self.thought_history if t.observation]\n        }\n```\n\n### ReAct Implementation\n\n```python\nclass ReActAgent(BaseAgent):\n    \"\"\"ReAct (Reason + Act) agent implementation\"\"\"\n    \n    def get_system_prompt(self) -> str:\n        return \"\"\"You are a ReAct agent. For each step:\n1. Think about what to do\n2. Act by calling a tool or responding\n3. Observe the result\n\nFormat your response as:\nThought: [your reasoning]\nAction: [tool_name] [arguments] OR respond [your response]\nObservation: [result of action]\"\"\"\n    \n    async def think(self, task: str) -> Thought:\n        \"\"\"ReAct-style reasoning\"\"\"\n        context = self.build_context()\n        \n        # Prompt for ReAct format\n        prompt = f\"\"\"Task: {task}\n\n{context}\n\nFollow this format:\nThought: [your reasoning]\nAction: [tool_to_use] [arguments]\nObservation: [result]\"\"\"\n        \n        response = await self.llm.chat([\n            {\"role\": \"system\", \"content\": self.get_system_prompt()},\n            {\"role\": \"user\", \"content\": prompt}\n        ])\n        \n        # Parse response\n        return self.parse_response(response.content)\n    \n    def parse_response(self, response: str) -> Thought:\n        \"\"\"Parse ReAct format response\"\"\"\n        lines = response.strip().split(\"\\n\")\n        thought = Thought(content=\"\")\n        \n        for line in lines:\n            if line.startswith(\"Thought:\"):\n                thought.content = line[8:].strip()\n            elif line.startswith(\"Action:\"):\n                action = line[7:].strip()\n                if action.startswith(\"respond\"):\n                    thought.action = action[8:].strip()\n                else:\n                    # Parse tool call\n                    parts = action.split(\" \", 1)\n                    thought.action = parts[0] if len(parts) > 1 else action\n            elif line.startswith(\"Observation:\"):\n                thought.observation = line[12:].strip()\n        \n        return thought\n```\n\n-----\n\n## Tool Systems\n\n### Tool Definition and Execution\n\n```python\nfrom abc import ABC, abstractmethod\nfrom typing import Any, Dict\nimport json\n\nclass Tool(ABC):\n    \"\"\"Base class for agent tools\"\"\"\n    \n    @property\n    @abstractmethod\n    def name(self) -> str:\n        \"\"\"Tool name\"\"\"\n        pass\n    \n    @property\n    @abstractmethod\n    def description(self) -> str:\n        \"\"\"Tool description for LLM\"\"\"\n        pass\n    \n    @property\n    @abstractmethod\n    def input_schema(self) -> Dict:\n        \"\"\"JSON schema for tool input\"\"\"\n        pass\n    \n    @abstractmethod\n    async def execute(self, **kwargs) -> str:\n        \"\"\"Execute the tool\"\"\"\n        pass\n\nclass SearchTool(Tool):\n    \"\"\"Web search tool\"\"\"\n    \n    @property\n    def name(self) -> str:\n        return \"search\"\n    \n    @property\n    def description(self) -> str:\n        return \"Search the web for information. Use this when you need current information or facts not in your training data.\"\n    \n    @property\n    def input_schema(self) -> Dict:\n        return {\n            \"type\": \"object\",\n            \"properties\": {\n                \"query\": {\"type\": \"string\", \"description\": \"Search query\"},\n                \"max_results\": {\"type\": \"integer\", \"default\": 5}\n            },\n            \"required\": [\"query\"]\n        }\n    \n    async def execute(self, query: str, max_results: int = 5) -> str:\n        # Implementation would call search API\n        results = await self.search_api.search(query, max_results)\n        return json.dumps(results)\n\nclass CodeExecutionTool(Tool):\n    \"\"\"Code execution tool\"\"\"\n    \n    @property\n    def name(self) -> str:\n        return \"execute_code\"\n    \n    @property\n    def description(self) -> str:\n        return \"Execute Python code in a sandboxed environment. Use this for calculations, data processing, or testing code snippets.\"\n    \n    @property\n    def input_schema(self) -> Dict:\n        return {\n            \"type\": \"object\",\n            \"properties\": {\n                \"code\": {\"type\": \"string\", \"description\": \"Python code to execute\"},\n                \"timeout\": {\"type\": \"integer\", \"default\": 30}\n            },\n            \"required\": [\"code\"]\n        }\n    \n    async def execute(self, code: str, timeout: int = 30) -> str:\n        # Would execute in sandbox\n        result = await self.sandbox.execute(code, timeout)\n        return str(result)\n\nclass FileSystemTool(Tool):\n    \"\"\"File system operations\"\"\"\n    \n    @property\n    def name(self) -> str:\n        return \"file_operations\"\n    \n    @property\n    def description(self) -> str:\n        return \"Read, write, or list files in the working directory.\"\n    \n    @property\n    def input_schema(self) -> Dict:\n        return {\n            \"type\": \"object\",\n            \"properties\": {\n                \"operation\": {\"type\": \"string\", \"enum\": [\"read\", \"write\", \"list\"]},\n                \"path\": {\"type\": \"string\"},\n                \"content\": {\"type\": \"string\"}\n            },\n            \"required\": [\"operation\", \"path\"]\n        }\n    \n    async def execute(self, operation: str, path: str, content: str = None) -> str:\n        if operation == \"read\":\n            return self.read_file(path)\n        elif operation == \"write\":\n            return self.write_file(path, content)\n        elif operation == \"list\":\n            return self.list_directory(path)\n```\n\n### Tool Manager\n\n```python\nclass ToolManager:\n    \"\"\"Manages available tools for the agent\"\"\"\n    \n    def __init__(self):\n        self.tools: Dict[str, Tool] = {}\n        self.tool_descriptions: List[Dict] = []\n    \n    def register(self, tool: Tool):\n        \"\"\"Register a new tool\"\"\"\n        self.tools[tool.name] = tool\n        self.tool_descriptions.append({\n            \"name\": tool.name,\n            \"description\": tool.description,\n            \"input_schema\": tool.input_schema\n        })\n    \n    def get_tool(self, name: str) -> Optional[Tool]:\n        \"\"\"Get tool by name\"\"\"\n        return self.tools.get(name)\n    \n    def get_descriptions(self) -> str:\n        \"\"\"Get formatted tool descriptions for LLM\"\"\"\n        desc = \"Available tools:\\n\"\n        for t in self.tool_descriptions:\n            desc += f\"- {t['name']}: {t['description']}\\n\"\n            desc += f\"  Input: {json.dumps(t['input_schema'])}\\n\"\n        return desc\n```\n\n-----\n\n## Memory Systems\n\n### Working Memory\n\n```python\nclass WorkingMemory:\n    \"\"\"Short-term memory for current task\"\"\"\n    \n    def __init__(self, max_items: int = 10):\n        self.max_items = max_items\n        self.items: List[Dict] = []\n    \n    def add(self, item: Dict):\n        \"\"\"Add item to working memory\"\"\"\n        self.items.append({\n            **item,\n            \"timestamp\": datetime.now()\n        })\n        \n        # Keep only recent items\n        if len(self.items) > self.max_items:\n            self.items = self.items[-self.max_items:]\n    \n    def get_recent(self, n: int = 5) -> List[Dict]:\n        \"\"\"Get n most recent items\"\"\"\n        return self.items[-n:]\n    \n    def clear(self):\n        \"\"\"Clear working memory\"\"\"\n        self.items = []\n    \n    def summarize(self) -> str:\n        \"\"\"Get text summary of working memory\"\"\"\n        if not self.items:\n            return \"No items in working memory\"\n        \n        summary = \"Recent items:\\n\"\n        for item in self.items[-5:]:\n            summary += f\"- {item.get('type', 'unknown')}: {item.get('content', '')[:100]}\\n\"\n        return summary\n```\n\n### Semantic Memory\n\n```python\nclass SemanticMemory:\n    \"\"\"Long-term semantic memory using embeddings\"\"\"\n    \n    def __init__(self, vector_store, embedding_model):\n        self.vector_store = vector_store\n        self.embedding_model = embedding_model\n    \n    async def store(self, content: str, metadata: Dict = None):\n        \"\"\"Store content in semantic memory\"\"\"\n        embedding = await self.embedding_model.embed(content)\n        \n        await self.vector_store.insert({\n            \"id\": str(uuid.uuid4()),\n            \"embedding\": embedding,\n            \"content\": content,\n            \"metadata\": metadata or {},\n            \"timestamp\": datetime.now().isoformat()\n        })\n    \n    async def retrieve(self, query: str, top_k: int = 5) -> str:\n        \"\"\"Retrieve relevant memories\"\"\"\n        query_embedding = await self.embedding_model.embed(query)\n        \n        results = await self.vector_store.search(\n            query_embedding,\n            top_k=top_k\n        )\n        \n        return \"\\n\".join([\n            f\"- {r['content']}\" for r in results\n        ])\n    \n    async def retrieve_with_scores(self, query: str, top_k: int = 5) -> List[Dict]:\n        \"\"\"Retrieve with similarity scores\"\"\"\n        query_embedding = await self.embedding_model.embed(query)\n        \n        return await self.vector_store.search(\n            query_embedding,\n            top_k=top_k\n        )\n```\n\n### Episodic Memory\n\n```python\nclass EpisodicMemory:\n    \"\"\"Memory of past agent experiences\"\"\"\n    \n    def __init__(self, storage):\n        self.storage = storage\n    \n    async def store_episode(self, episode: Dict):\n        \"\"\"Store a complete episode\"\"\"\n        await self.storage.insert({\n            \"id\": str(uuid.uuid4()),\n            \"task\": episode.get(\"task\"),\n            \"actions\": episode.get(\"actions\", []),\n            \"outcome\": episode.get(\"outcome\"),\n            \"success\": episode.get(\"success\", False),\n            \"reflection\": episode.get(\"reflection\"),\n            \"timestamp\": datetime.now().isoformat()\n        })\n    \n    async def get_similar_episodes(self, task: str, top_k: int = 3) -> List[Dict]:\n        \"\"\"Find similar past episodes\"\"\"\n        # Would use embeddings or keyword matching\n        return await self.storage.query(\n            f\"task:{task}\",\n            limit=top_k\n        )\n    \n    async def get_success_rate(self, task_type: str = None) -> float:\n        \"\"\"Calculate success rate\"\"\"\n        # Query and calculate\n        return 0.75  # Placeholder\n```\n\n-----\n\n## Planning Systems\n\n### Plan-and-Execute Agent\n\n```python\nclass PlanExecuteAgent(BaseAgent):\n    \"\"\"Agent that plans before executing\"\"\"\n    \n    async def run(self, task: str) -> Dict:\n        # Planning phase\n        plan = await self.create_plan(task)\n        \n        # Execution phase\n        results = []\n        for step in plan[\"steps\"]:\n            result = await self.execute_step(step)\n            results.append(result)\n            \n            # Check for plan deviations\n            if not self.validate_step(result, step):\n                # Replan if needed\n                plan = await self.replan(task, plan, results)\n        \n        return self.format_result(results)\n    \n    async def create_plan(self, task: str) -> Dict:\n        \"\"\"Create initial plan\"\"\"\n        prompt = f\"\"\"Create a step-by-step plan to accomplish this task:\nTask: {task}\n\nFormat as:\nPlan: [brief description]\nSteps:\n1. [first step]\n2. [second step]\n...\"\"\"\n\n        response = await self.llm.chat([\n            {\"role\": \"system\", \"content\": \"You are a planning agent.\"},\n            {\"role\": \"user\", \"content\": prompt}\n        ])\n        \n        return self.parse_plan(response.content)\n    \n    async def execute_step(self, step: Dict) -> Dict:\n        \"\"\"Execute a single plan step\"\"\"\n        # Execute using tools\n        result = await self.think_and_act(step[\"description\"])\n        \n        return {\n            \"step\": step,\n            \"result\": result,\n            \"success\": self.evaluate_success(result, step[\"goal\"])\n        }\n    \n    def parse_plan(self, response: str) -> Dict:\n        \"\"\"Parse plan from LLM response\"\"\"\n        lines = response.strip().split(\"\\n\")\n        plan = {\"description\": \"\", \"steps\": []}\n        \n        for line in lines:\n            if line.startswith(\"Plan:\"):\n                plan[\"description\"] = line[5:].strip()\n            elif line[0].isdigit() and \". \" in line:\n                step = line.split(\". \", 1)[1].strip()\n                plan[\"steps\"].append({\n                    \"description\": step,\n                    \"goal\": step  # Simplified\n                })\n        \n        return plan\n```\n\n### Tree of Thoughts\n\n```python\nclass TreeOfThoughtsAgent:\n    \"\"\"Agent using Tree of Thoughts reasoning\"\"\"\n    \n    def __init__(self, llm, num_thoughts: int = 3, max_depth: int = 3):\n        self.llm = llm\n        self.num_thoughts = num_thoughts\n        self.max_depth = max_depth\n    \n    async def solve(self, task: str) -> str:\n        \"\"\"Solve task using tree of thoughts\"\"\"\n        root = ThoughtNode(task, None)\n        \n        # Generate initial thoughts\n        await self.expand_node(root)\n        \n        # Search tree for best solution\n        best = await self.search(root)\n        \n        return best.content\n    \n    async def expand_node(self, node: ThoughtNode):\n        \"\"\"Expand a node with multiple thoughts\"\"\"\n        if node.depth >= self.max_depth:\n            return\n        \n        # Generate multiple thoughts\n        for _ in range(self.num_thoughts):\n            thought = await self.generate_thought(node)\n            child = ThoughtNode(thought, node)\n            node.children.append(child)\n            \n            # Evaluate child\n            child.score = await self.evaluate(child)\n            \n            # Expand if promising\n            if child.score > 0.5:\n                await self.expand_node(child)\n    \n    async def generate_thought(self, node: ThoughtNode) -> str:\n        \"\"\"Generate next thought\"\"\"\n        context = node.get_path()\n        \n        prompt = f\"\"\"Given this reasoning chain:\n{context}\n\nGenerate the next thought step:\nThought:\"\"\"\n        \n        response = await self.llm.chat([\n            {\"role\": \"user\", \"content\": prompt}\n        ])\n        \n        return response.content\n    \n    async def search(self, node: ThoughtNode) -> ThoughtNode:\n        \"\"\"Search for best solution\"\"\"\n        if not node.children:\n            return node\n        \n        # DFS with pruning\n        best = node\n        for child in node.children:\n            candidate = await self.search(child)\n            if candidate.score > best.score:\n                best = candidate\n        \n        return best\n\nclass ThoughtNode:\n    def __init__(self, content: str, parent):\n        self.content = content\n        self.parent = parent\n        self.children: List[ThoughtNode] = []\n        self.score = 0.0\n        self.depth = 0 if parent is None else parent.depth + 1\n    \n    def get_path(self) -> str:\n        \"\"\"Get full reasoning path\"\"\"\n        path = []\n        node = self\n        while node:\n            path.append(node.content)\n            node = node.parent\n        return \"\\n\".join(reversed(path))\n```\n\n-----\n\n## Evaluation Frameworks\n\n### Agent Evaluation Metrics\n\n```python\nfrom dataclasses import dataclass\nfrom typing import List\n\n@dataclass\nclass EvaluationResult:\n    \"\"\"Result of agent evaluation\"\"\"\n    task: str\n    success: bool\n    steps_taken: int\n    final_response: str\n    expected_outcome: str\n    metrics: Dict[str, float]\n\nclass AgentEvaluator:\n    \"\"\"Evaluates agent performance\"\"\"\n    \n    def __init__(self, metrics: List[str] = None):\n        self.metrics = metrics or [\n            \"success_rate\",\n            \"efficiency\",\n            \"accuracy\",\n            \"tool_usage\",\n            \"error_rate\"\n        ]\n    \n    async def evaluate(\n        self,\n        agent: BaseAgent,\n        test_cases: List[Dict]\n    ) -> Dict:\n        \"\"\"Evaluate agent on test cases\"\"\"\n        results = []\n        \n        for test in test_cases:\n            result = await self.run_test(agent, test)\n            results.append(result)\n        \n        # Aggregate metrics\n        return self.aggregate_results(results)\n    \n    async def run_test(\n        self,\n        agent: BaseAgent,\n        test: Dict\n    ) -> EvaluationResult:\n        \"\"\"Run single test case\"\"\"\n        response = await agent.run(test[\"task\"])\n        \n        # Check success\n        success = self.check_success(response, test.get(\"expected\"))\n        \n        return EvaluationResult(\n            task=test[\"task\"],\n            success=success,\n            steps_taken=len(response.get(\"thoughts\", [])),\n            final_response=response.get(\"response\", \"\"),\n            expected_outcome=test.get(\"expected\", \"\"),\n            metrics=self.compute_metrics(response, test)\n        )\n    \n    def compute_metrics(self, response: Dict, test: Dict) -> Dict:\n        \"\"\"Compute individual metrics\"\"\"\n        return {\n            \"efficiency\": 1.0 \u002F (len(response.get(\"thoughts\", [])) + 1),\n            \"tool_usage\": len([t for t in response.get(\"actions\", []) if t]),\n        }\n    \n    def aggregate_results(self, results: List[EvaluationResult]) -> Dict:\n        \"\"\"Aggregate results into summary\"\"\"\n        total = len(results)\n        successes = sum(1 for r in results if r.success)\n        \n        return {\n            \"success_rate\": successes \u002F total,\n            \"total_tests\": total,\n            \"avg_steps\": sum(r.steps_taken for r in results) \u002F total,\n            \"per_task\": {r.task: r.success for r in results}\n        }\n```\n\n### Benchmarking\n\n```python\nclass AgentBenchmark:\n    \"\"\"Benchmark agent performance against baselines\"\"\"\n    \n    BENCHMARKS = {\n        \"hotpotqa\": {\"type\": \"retrieval\", \"metrics\": [\"accuracy\"]},\n        \"math\": {\"type\": \"reasoning\", \"metrics\": [\"accuracy\"]},\n        \"tooluse\": {\"type\": \"tool_use\", \"metrics\": [\"success_rate\"]},\n        \"api_bank\": {\"type\": \"api_call\", \"metrics\": [\"accuracy\"]}\n    }\n    \n    async def run_benchmark(\n        self,\n        agent: BaseAgent,\n        benchmark: str\n    ) -> Dict:\n        \"\"\"Run specific benchmark\"\"\"\n        if benchmark not in self.BENCHMARKS:\n            raise ValueError(f\"Unknown benchmark: {benchmark}\")\n        \n        test_cases = self.load_benchmark(benchmark)\n        evaluator = AgentEvaluator()\n        \n        results = await evaluator.evaluate(agent, test_cases)\n        \n        return {\n            \"benchmark\": benchmark,\n            **results\n        }\n```\n\n-----\n\n## Multi-Agent Systems\n\n### Agent Collaboration\n\n```python\nclass MultiAgentOrchestrator:\n    \"\"\"Orchestrates multiple specialized agents\"\"\"\n    \n    def __init__(self):\n        self.agents: Dict[str, BaseAgent] = {}\n        self.task_queue: asyncio.Queue = asyncio.Queue()\n    \n    def register_agent(self, name: str, agent: BaseAgent, capabilities: List[str]):\n        \"\"\"Register an agent with capabilities\"\"\"\n        self.agents[name] = {\n            \"agent\": agent,\n            \"capabilities\": capabilities,\n            \"busy\": False\n        }\n    \n    async def assign_task(self, task: str) -> Dict:\n        \"\"\"Assign task to best available agent\"\"\"\n        # Analyze task requirements\n        required = self.analyze_requirements(task)\n        \n        # Find suitable agent\n        agent_info = self.select_agent(required)\n        \n        if not agent_info:\n            return {\"status\": \"no_agent\", \"task\": task}\n        \n        # Execute task\n        agent = agent_info[\"agent\"]\n        result = await agent.run(task)\n        \n        return {\n            \"status\": \"completed\",\n            \"agent\": agent_info[\"name\"],\n            \"result\": result\n        }\n    \n    def analyze_requirements(self, task: str) -> List[str]:\n        \"\"\"Analyze task to determine requirements\"\"\"\n        # Simplified - would use LLM\n        keywords = {\n            \"search\": [\"search\", \"find\", \"look up\"],\n            \"code\": [\"code\", \"implement\", \"program\"],\n            \"write\": [\"write\", \"create\", \"draft\"]\n        }\n        \n        required = []\n        for capability, patterns in keywords.items():\n            if any(p in task.lower() for p in patterns):\n                required.append(capability)\n        \n        return required\n    \n    def select_agent(self, requirements: List[str]) -> Optional[Dict]:\n        \"\"\"Select agent based on requirements\"\"\"\n        for name, info in self.agents.items():\n            caps = set(info[\"capabilities\"])\n            reqs = set(requirements)\n            \n            if reqs.issubset(caps) and not info[\"busy\"]:\n                info[\"busy\"] = True\n                return {\"name\": name, **info}\n        \n        return None\n```\n\n### Debate and Consensus\n\n```python\nclass DebateOrchestrator:\n    \"\"\"Multi-agent debate system\"\"\"\n    \n    def __init__(self, num_agents: int = 3):\n        self.agents = [BaseAgent(config) for _ in range(num_agents)]\n        self.max_rounds = 3\n    \n    async def debate(self, topic: str) -> Dict:\n        \"\"\"Run debate on topic\"\"\"\n        # Initial statements\n        statements = []\n        for agent in self.agents:\n            statement = await agent.run(f\"Provide your position on: {topic}\")\n            statements.append(statement)\n        \n        # Debate rounds\n        for round in range(self.max_rounds):\n            # Each agent responds to others\n            responses = []\n            for i, agent in enumerate(self.agents):\n                other_statements = [s for j, s in enumerate(statements) if j != i]\n                response = await agent.run(\n                    f\"Debate topic: {topic}\\n\\n\"\n                    f\"Other positions:\\n\" + \"\\n\".join(other_statements)\n                )\n                statements[i] = response\n                responses.append(response)\n        \n        # Reach consensus or summarize\n        consensus = await self.find_consensus(statements)\n        \n        return {\n            \"statements\": statements,\n            \"consensus\": consensus,\n            \"rounds\": self.max_rounds\n        }\n```\n\n-----\n\n## Best Practices\n\n1. **Start Simple** — Begin with basic agents before adding complexity.\n\n2. **Tool Design Matters** — Design tools with clear, specific purposes and well-defined schemas.\n\n3. **Handle Failures Gracefully** — Implement retry logic and fallback strategies.\n\n4. **Monitor and Log** — Track agent decisions for debugging and improvement.\n\n5. **Evaluate Continuously** — Benchmark agents on realistic test cases.\n\n6. **Guardrails Are Essential** — Implement safety measures for autonomous actions.\n\n7. **Memory Management** — Balance context retention with token efficiency.\n\n8. **Plan for Scale** — Consider multi-agent architectures for complex tasks.\n","# Agentic AI — Implementation Guide\n\nCovers: **Agent Architectures · Tool Use · Memory Systems · Planning · Evaluation · Multi-Agent Systems**\n\n-----\n\n## Understanding Agentic AI\n\n### What Makes an AI \"Agentic\"?\n\nAn agentic AI system differs from traditional AI assistants in several fundamental ways. While a standard language model responds to each prompt independently, an agentic system maintains state across interactions, takes autonomous actions to achieve goals, and can plan multi-step sequences of operations.\n\nThe key characteristics that define agentic AI include: autonomy in decision-making without requiring constant human guidance, the ability to plan and execute multi-step workflows, the capacity to use external tools and APIs to interact with the world, memory systems that preserve context across interactions, and feedback mechanisms that enable learning and adaptation.\n\n**Agentic systems can be categorized by their complexity:**\n\nSimple reflex agents respond to stimuli based on predetermined rules. Goal-based agents work toward specific objectives using planning algorithms. Utility-based agents maximize expected utility through optimization. Learning agents improve performance through experience. Multi-agent systems involve multiple AI agents collaborating or competing.\n\n**Common Agent Architectures:**\n\n- **ReAct (Reason + Act)** — Combines reasoning traces with action execution\n- **Reflexion** — Adds verbal reinforcement learning for self-reflection\n- **Tool Use Agents** — Integrate external tools and APIs into reasoning\n- **Plan-and-Execute** — Separates planning from execution phases\n- **Multi-Agent** — Multiple specialized agents working together\n\n### When to Use Agentic Systems\n\nAgentic systems excel in scenarios requiring complex multi-step reasoning, dynamic tool orchestration, persistent context across sessions, autonomous decision-making, iterative refinement, or coordination of multiple specialized components. They are particularly valuable for building AI assistants that can take actions rather than just generating text.\n\nTraditional completion-based AI remains superior for simple question-answering, content generation, summarization, and single-turn interactions. The complexity of agentic systems is justified when the task genuinely requires persistent state, tool use, or multi-step execution.\n\n-----\n\n## Agent Architecture Design\n\n### Core Agent Loop\n\n```python\nfrom dataclasses import dataclass, field\nfrom typing import List, Dict, Any, Optional, Callable\nfrom enum import Enum\nfrom datetime import datetime\n\nclass AgentState(Enum):\n    IDLE = \"idle\"\n    REASONING = \"reasoning\"\n    ACTING = \"acting\"\n    OBSERVING = \"observing\"\n    FINISHED = \"finished\"\n    ERROR = \"error\"\n\n@dataclass\nclass Thought:\n    \"\"\"A single thought in the agent's reasoning chain\"\"\"\n    content: str\n    timestamp: datetime = field(default_factory=datetime.now)\n    action: Optional[str] = None\n    observation: Optional[str] = None\n\n@dataclass\nclass AgentConfig:\n    \"\"\"Configuration for agent behavior\"\"\"\n    model: str = \"claude-sonnet-4-5-20251120\"\n    max_iterations: int = 100\n    max_tokens_per_iteration: int = 4096\n    temperature: float = 0.7\n    tools: List[Any] = field(default_factory=list)\n    memory_system: Optional['MemorySystem'] = None\n    planning_enabled: bool = True\n    reflection_enabled: bool = True\n\nclass BaseAgent:\n    \"\"\"Core agent implementation\"\"\"\n    \n    def __init__(self, config: AgentConfig, llm_client):\n        self.config = config\n        self.llm = llm_client\n        self.state = AgentState.IDLE\n        self.thought_history: List[Thought] = []\n        self.tools = {tool.name: tool for tool in config.tools}\n    \n    async def run(self, task: str) -> Dict[str, Any]:\n        \"\"\"Main agent loop\"\"\"\n        self.task = task\n        self.thought_history = []\n        \n        for iteration in range(self.config.max_iterations):\n            # Think phase\n            thought = await self.think(task)\n            self.thought_history.append(thought)\n            \n            # Act phase\n            if thought.action:\n                result = await self.act(thought.action)\n                thought.observation = result\n                \n                # Check if task is complete\n                if self.is_complete(result):\n                    return self.format_result()\n            else:\n                # No action needed, provide final response\n                return {\"status\": \"completed\", \"response\": thought.content}\n        \n        return {\"status\": \"max_iterations\", \"thoughts\": self.thought_history}\n    \n    async def think(self, task: str) -> Thought:\n        \"\"\"Reason about the current state and determine next action\"\"\"\n        self.state = AgentState.REASONING\n        \n        # Build context from history and memory\n        context = self.build_context()\n        \n        # Get LLM response with action\n        response = await self.llm.chat([\n            {\"role\": \"system\", \"content\": self.get_system_prompt()},\n            {\"role\": \"user\", \"content\": f\"Task: {task}\\n\\n{context}\"}\n        ])\n        \n        return Thought(content=response.content, action=response.tool_use)\n    \n    async def act(self, action: str) -> str:\n        \"\"\"Execute the determined action\"\"\"\n        self.state = AgentState.ACTING\n        \n        if action in self.tools:\n            return await self.tools[action].execute()\n        else:\n            return action  # Plain text response\n    \n    def build_context(self) -> str:\n        \"\"\"Build context from thought history and memory\"\"\"\n        history = \"\\n\".join([\n            f\"- {t.content}\" + (f\" -> {t.observation}\" if t.observation else \"\")\n            for t in self.thought_history[-5:]\n        ])\n        \n        memory = \"\"\n        if self.config.memory_system:\n            memory = f\"\\nRelevant memory:\\n{self.config.memory_system.retrieve(self.task)}\"\n        \n        return f\"History:\\n{history}{memory}\"\n    \n    def is_complete(self, result: str) -> bool:\n        \"\"\"Determine if task is complete\"\"\"\n        completion_indicators = [\n            \"task complete\",\n            \"finished\",\n            \"successfully\",\n            \"delivered\"\n        ]\n        return any(indicator in result.lower() for indicator in completion_indicators)\n    \n    def format_result(self) -> Dict[str, Any]:\n        \"\"\"Format the final result\"\"\"\n        return {\n            \"status\": \"completed\",\n            \"thoughts\": [t.content for t in self.thought_history],\n            \"actions\": [t.action for t in self.thought_history if t.action],\n            \"observations\": [t.observation for t in self.thought_history if t.observation]\n        }\n```\n\n### ReAct Implementation\n\n```python\nclass ReActAgent(BaseAgent):\n    \"\"\"ReAct (Reason + Act) agent implementation\"\"\"\n    \n    def get_system_prompt(self) -> str:\n        return \"\"\"You are a ReAct agent. For each step:\n1. Think about what to do\n2. Act by calling a tool or responding\n3. Observe the result\n\nFormat your response as:\nThought: [your reasoning]\nAction: [tool_name] [arguments] OR respond [your response]\nObservation: [result of action]\"\"\"\n    \n    async def think(self, task: str) -> Thought:\n        \"\"\"ReAct-style reasoning\"\"\"\n        context = self.build_context()\n        \n        # Prompt for ReAct format\n        prompt = f\"\"\"Task: {task}\n\n{context}\n\nFollow this format:\nThought: [your reasoning]\nAction: [tool_to_use] [arguments]\nObservation: [result]\"\"\"\n        \n        response = await self.llm.chat([\n            {\"role\": \"system\", \"content\": self.get_system_prompt()},\n            {\"role\": \"user\", \"content\": prompt}\n        ])\n        \n        # Parse response\n        return self.parse_response(response.content)\n    \n    def parse_response(self, response: str) -> Thought:\n        \"\"\"Parse ReAct format response\"\"\"\n        lines = response.strip().split(\"\\n\")\n        thought = Thought(content=\"\")\n        \n        for line in lines:\n            if line.startswith(\"Thought:\"):\n                thought.content = line[8:].strip()\n            elif line.startswith(\"Action:\"):\n                action = line[7:].strip()\n                if action.startswith(\"respond\"):\n                    thought.action = action[8:].strip()\n                else:\n                    # Parse tool call\n                    parts = action.split(\" \", 1)\n                    thought.action = parts[0] if len(parts) > 1 else action\n            elif line.startswith(\"Observation:\"):\n                thought.observation = line[12:].strip()\n        \n        return thought\n```\n\n-----\n\n## Tool Systems\n\n### Tool Definition and Execution\n\n```python\nfrom abc import ABC, abstractmethod\nfrom typing import Any, Dict\nimport json\n\nclass Tool(ABC):\n    \"\"\"Base class for agent tools\"\"\"\n    \n    @property\n    @abstractmethod\n    def name(self) -> str:\n        \"\"\"Tool name\"\"\"\n        pass\n    \n    @property\n    @abstractmethod\n    def description(self) -> str:\n        \"\"\"Tool description for LLM\"\"\"\n        pass\n    \n    @property\n    @abstractmethod\n    def input_schema(self) -> Dict:\n        \"\"\"JSON schema for tool input\"\"\"\n        pass\n    \n    @abstractmethod\n    async def execute(self, **kwargs) -> str:\n        \"\"\"Execute the tool\"\"\"\n        pass\n\nclass SearchTool(Tool):\n    \"\"\"Web search tool\"\"\"\n    \n    @property\n    def name(self) -> str:\n        return \"search\"\n    \n    @property\n    def description(self) -> str:\n        return \"Search the web for information. Use this when you need current information or facts not in your training data.\"\n    \n    @property\n    def input_schema(self) -> Dict:\n        return {\n            \"type\": \"object\",\n            \"properties\": {\n                \"query\": {\"type\": \"string\", \"description\": \"Search query\"},\n                \"max_results\": {\"type\": \"integer\", \"default\": 5}\n            },\n            \"required\": [\"query\"]\n        }\n    \n    async def execute(self, query: str, max_results: int = 5) -> str:\n        # Implementation would call search API\n        results = await self.search_api.search(query, max_results)\n        return json.dumps(results)\n\nclass CodeExecutionTool(Tool):\n    \"\"\"Code execution tool\"\"\"\n    \n    @property\n    def name(self) -> str:\n        return \"execute_code\"\n    \n    @property\n    def description(self) -> str:\n        return \"Execute Python code in a sandboxed environment. Use this for calculations, data processing, or testing code snippets.\"\n    \n    @property\n    def input_schema(self) -> Dict:\n        return {\n            \"type\": \"object\",\n            \"properties\": {\n                \"code\": {\"type\": \"string\", \"description\": \"Python code to execute\"},\n                \"timeout\": {\"type\": \"integer\", \"default\": 30}\n            },\n            \"required\": [\"code\"]\n        }\n    \n    async def execute(self, code: str, timeout: int = 30) -> str:\n        # Would execute in sandbox\n        result = await self.sandbox.execute(code, timeout)\n        return str(result)\n\nclass FileSystemTool(Tool):\n    \"\"\"File system operations\"\"\"\n    \n    @property\n    def name(self) -> str:\n        return \"file_operations\"\n    \n    @property\n    def description(self) -> str:\n        return \"Read, write, or list files in the working directory.\"\n    \n    @property\n    def input_schema(self) -> Dict:\n        return {\n            \"type\": \"object\",\n            \"properties\": {\n                \"operation\": {\"type\": \"string\", \"enum\": [\"read\", \"write\", \"list\"]},\n                \"path\": {\"type\": \"string\"},\n                \"content\": {\"type\": \"string\"}\n            },\n            \"required\": [\"operation\", \"path\"]\n        }\n    \n    async def execute(self, operation: str, path: str, content: str = None) -> str:\n        if operation == \"read\":\n            return self.read_file(path)\n        elif operation == \"write\":\n            return self.write_file(path, content)\n        elif operation == \"list\":\n            return self.list_directory(path)\n```\n\n### Tool Manager\n\n```python\nclass ToolManager:\n    \"\"\"Manages available tools for the agent\"\"\"\n    \n    def __init__(self):\n        self.tools: Dict[str, Tool] = {}\n        self.tool_descriptions: List[Dict] = []\n    \n    def register(self, tool: Tool):\n        \"\"\"Register a new tool\"\"\"\n        self.tools[tool.name] = tool\n        self.tool_descriptions.append({\n            \"name\": tool.name,\n            \"description\": tool.description,\n            \"input_schema\": tool.input_schema\n        })\n    \n    def get_tool(self, name: str) -> Optional[Tool]:\n        \"\"\"Get tool by name\"\"\"\n        return self.tools.get(name)\n    \n    def get_descriptions(self) -> str:\n        \"\"\"Get formatted tool descriptions for LLM\"\"\"\n        desc = \"Available tools:\\n\"\n        for t in self.tool_descriptions:\n            desc += f\"- {t['name']}: {t['description']}\\n\"\n            desc += f\"  Input: {json.dumps(t['input_schema'])}\\n\"\n        return desc\n```\n\n-----\n\n## Memory Systems\n\n### Working Memory\n\n```python\nclass WorkingMemory:\n    \"\"\"Short-term memory for current task\"\"\"\n    \n    def __init__(self, max_items: int = 10):\n        self.max_items = max_items\n        self.items: List[Dict] = []\n    \n    def add(self, item: Dict):\n        \"\"\"Add item to working memory\"\"\"\n        self.items.append({\n            **item,\n            \"timestamp\": datetime.now()\n        })\n        \n        # Keep only recent items\n        if len(self.items) > self.max_items:\n            self.items = self.items[-self.max_items:]\n    \n    def get_recent(self, n: int = 5) -> List[Dict]:\n        \"\"\"Get n most recent items\"\"\"\n        return self.items[-n:]\n    \n    def clear(self):\n        \"\"\"Clear working memory\"\"\"\n        self.items = []\n    \n    def summarize(self) -> str:\n        \"\"\"Get text summary of working memory\"\"\"\n        if not self.items:\n            return \"No items in working memory\"\n        \n        summary = \"Recent items:\\n\"\n        for item in self.items[-5:]:\n            summary += f\"- {item.get('type', 'unknown')}: {item.get('content', '')[:100]}\\n\"\n        return summary\n```\n\n### Semantic Memory\n\n```python\nclass SemanticMemory:\n    \"\"\"Long-term semantic memory using embeddings\"\"\"\n    \n    def __init__(self, vector_store, embedding_model):\n        self.vector_store = vector_store\n        self.embedding_model = embedding_model\n    \n    async def store(self, content: str, metadata: Dict = None):\n        \"\"\"Store content in semantic memory\"\"\"\n        embedding = await self.embedding_model.embed(content)\n        \n        await self.vector_store.insert({\n            \"id\": str(uuid.uuid4()),\n            \"embedding\": embedding,\n            \"content\": content,\n            \"metadata\": metadata or {},\n            \"timestamp\": datetime.now().isoformat()\n        })\n    \n    async def retrieve(self, query: str, top_k: int = 5) -> str:\n        \"\"\"Retrieve relevant memories\"\"\"\n        query_embedding = await self.embedding_model.embed(query)\n        \n        results = await self.vector_store.search(\n            query_embedding,\n            top_k=top_k\n        )\n        \n        return \"\\n\".join([\n            f\"- {r['content']}\" for r in results\n        ])\n    \n    async def retrieve_with_scores(self, query: str, top_k: int = 5) -> List[Dict]:\n        \"\"\"Retrieve with similarity scores\"\"\"\n        query_embedding = await self.embedding_model.embed(query)\n        \n        return await self.vector_store.search(\n            query_embedding,\n            top_k=top_k\n        )\n```\n\n### Episodic Memory\n\n```python\nclass EpisodicMemory:\n    \"\"\"Memory of past agent experiences\"\"\"\n    \n    def __init__(self, storage):\n        self.storage = storage\n    \n    async def store_episode(self, episode: Dict):\n        \"\"\"Store a complete episode\"\"\"\n        await self.storage.insert({\n            \"id\": str(uuid.uuid4()),\n            \"task\": episode.get(\"task\"),\n            \"actions\": episode.get(\"actions\", []),\n            \"outcome\": episode.get(\"outcome\"),\n            \"success\": episode.get(\"success\", False),\n            \"reflection\": episode.get(\"reflection\"),\n            \"timestamp\": datetime.now().isoformat()\n        })\n    \n    async def get_similar_episodes(self, task: str, top_k: int = 3) -> List[Dict]:\n        \"\"\"Find similar past episodes\"\"\"\n        # Would use embeddings or keyword matching\n        return await self.storage.query(\n            f\"task:{task}\",\n            limit=top_k\n        )\n    \n    async def get_success_rate(self, task_type: str = None) -> float:\n        \"\"\"Calculate success rate\"\"\"\n        # Query and calculate\n        return 0.75  # Placeholder\n```\n\n-----\n\n## Planning Systems\n\n### Plan-and-Execute Agent\n\n```python\nclass PlanExecuteAgent(BaseAgent):\n    \"\"\"Agent that plans before executing\"\"\"\n    \n    async def run(self, task: str) -> Dict:\n        # Planning phase\n        plan = await self.create_plan(task)\n        \n        # Execution phase\n        results = []\n        for step in plan[\"steps\"]:\n            result = await self.execute_step(step)\n            results.append(result)\n            \n            # Check for plan deviations\n            if not self.validate_step(result, step):\n                # Replan if needed\n                plan = await self.replan(task, plan, results)\n        \n        return self.format_result(results)\n    \n    async def create_plan(self, task: str) -> Dict:\n        \"\"\"Create initial plan\"\"\"\n        prompt = f\"\"\"Create a step-by-step plan to accomplish this task:\nTask: {task}\n\nFormat as:\nPlan: [brief description]\nSteps:\n1. [first step]\n2. [second step]\n...\"\"\"\n\n        response = await self.llm.chat([\n            {\"role\": \"system\", \"content\": \"You are a planning agent.\"},\n            {\"role\": \"user\", \"content\": prompt}\n        ])\n        \n        return self.parse_plan(response.content)\n    \n    async def execute_step(self, step: Dict) -> Dict:\n        \"\"\"Execute a single plan step\"\"\"\n        # Execute using tools\n        result = await self.think_and_act(step[\"description\"])\n        \n        return {\n            \"step\": step,\n            \"result\": result,\n            \"success\": self.evaluate_success(result, step[\"goal\"])\n        }\n    \n    def parse_plan(self, response: str) -> Dict:\n        \"\"\"Parse plan from LLM response\"\"\"\n        lines = response.strip().split(\"\\n\")\n        plan = {\"description\": \"\", \"steps\": []}\n        \n        for line in lines:\n            if line.startswith(\"Plan:\"):\n                plan[\"description\"] = line[5:].strip()\n            elif line[0].isdigit() and \". \" in line:\n                step = line.split(\". \", 1)[1].strip()\n                plan[\"steps\"].append({\n                    \"description\": step,\n                    \"goal\": step  # Simplified\n                })\n        \n        return plan\n```\n\n### Tree of Thoughts\n\n```python\nclass TreeOfThoughtsAgent:\n    \"\"\"Agent using Tree of Thoughts reasoning\"\"\"\n    \n    def __init__(self, llm, num_thoughts: int = 3, max_depth: int = 3):\n        self.llm = llm\n        self.num_thoughts = num_thoughts\n        self.max_depth = max_depth\n    \n    async def solve(self, task: str) -> str:\n        \"\"\"Solve task using tree of thoughts\"\"\"\n        root = ThoughtNode(task, None)\n        \n        # Generate initial thoughts\n        await self.expand_node(root)\n        \n        # Search tree for best solution\n        best = await self.search(root)\n        \n        return best.content\n    \n    async def expand_node(self, node: ThoughtNode):\n        \"\"\"Expand a node with multiple thoughts\"\"\"\n        if node.depth >= self.max_depth:\n            return\n        \n        # Generate multiple thoughts\n        for _ in range(self.num_thoughts):\n            thought = await self.generate_thought(node)\n            child = ThoughtNode(thought, node)\n            node.children.append(child)\n            \n            # Evaluate child\n            child.score = await self.evaluate(child)\n            \n            # Expand if promising\n            if child.score > 0.5:\n                await self.expand_node(child)\n    \n    async def generate_thought(self, node: ThoughtNode) -> str:\n        \"\"\"Generate next thought\"\"\"\n        context = node.get_path()\n        \n        prompt = f\"\"\"Given this reasoning chain:\n{context}\n\nGenerate the next thought step:\nThought:\"\"\"\n        \n        response = await self.llm.chat([\n            {\"role\": \"user\", \"content\": prompt}\n        ])\n        \n        return response.content\n    \n    async def search(self, node: ThoughtNode) -> ThoughtNode:\n        \"\"\"Search for best solution\"\"\"\n        if not node.children:\n            return node\n        \n        # DFS with pruning\n        best = node\n        for child in node.children:\n            candidate = await self.search(child)\n            if candidate.score > best.score:\n                best = candidate\n        \n        return best\n\nclass ThoughtNode:\n    def __init__(self, content: str, parent):\n        self.content = content\n        self.parent = parent\n        self.children: List[ThoughtNode] = []\n        self.score = 0.0\n        self.depth = 0 if parent is None else parent.depth + 1\n    \n    def get_path(self) -> str:\n        \"\"\"Get full reasoning path\"\"\"\n        path = []\n        node = self\n        while node:\n            path.append(node.content)\n            node = node.parent\n        return \"\\n\".join(reversed(path))\n```\n\n-----\n\n## Evaluation Frameworks\n\n### Agent Evaluation Metrics\n\n```python\nfrom dataclasses import dataclass\nfrom typing import List\n\n@dataclass\nclass EvaluationResult:\n    \"\"\"Result of agent evaluation\"\"\"\n    task: str\n    success: bool\n    steps_taken: int\n    final_response: str\n    expected_outcome: str\n    metrics: Dict[str, float]\n\nclass AgentEvaluator:\n    \"\"\"Evaluates agent performance\"\"\"\n    \n    def __init__(self, metrics: List[str] = None):\n        self.metrics = metrics or [\n            \"success_rate\",\n            \"efficiency\",\n            \"accuracy\",\n            \"tool_usage\",\n            \"error_rate\"\n        ]\n    \n    async def evaluate(\n        self,\n        agent: BaseAgent,\n        test_cases: List[Dict]\n    ) -> Dict:\n        \"\"\"Evaluate agent on test cases\"\"\"\n        results = []\n        \n        for test in test_cases:\n            result = await self.run_test(agent, test)\n            results.append(result)\n        \n        # Aggregate metrics\n        return self.aggregate_results(results)\n    \n    async def run_test(\n        self,\n        agent: BaseAgent,\n        test: Dict\n    ) -> EvaluationResult:\n        \"\"\"Run single test case\"\"\"\n        response = await agent.run(test[\"task\"])\n        \n        # Check success\n        success = self.check_success(response, test.get(\"expected\"))\n        \n        return EvaluationResult(\n            task=test[\"task\"],\n            success=success,\n            steps_taken=len(response.get(\"thoughts\", [])),\n            final_response=response.get(\"response\", \"\"),\n            expected_outcome=test.get(\"expected\", \"\"),\n            metrics=self.compute_metrics(response, test)\n        )\n    \n    def compute_metrics(self, response: Dict, test: Dict) -> Dict:\n        \"\"\"Compute individual metrics\"\"\"\n        return {\n            \"efficiency\": 1.0 \u002F (len(response.get(\"thoughts\", [])) + 1),\n            \"tool_usage\": len([t for t in response.get(\"actions\", []) if t]),\n        }\n    \n    def aggregate_results(self, results: List[EvaluationResult]) -> Dict:\n        \"\"\"Aggregate results into summary\"\"\"\n        total = len(results)\n        successes = sum(1 for r in results if r.success)\n        \n        return {\n            \"success_rate\": successes \u002F total,\n            \"total_tests\": total,\n            \"avg_steps\": sum(r.steps_taken for r in results) \u002F total,\n            \"per_task\": {r.task: r.success for r in results}\n        }\n```\n\n### Benchmarking\n\n```python\nclass AgentBenchmark:\n    \"\"\"Benchmark agent performance against baselines\"\"\"\n    \n    BENCHMARKS = {\n        \"hotpotqa\": {\"type\": \"retrieval\", \"metrics\": [\"accuracy\"]},\n        \"math\": {\"type\": \"reasoning\", \"metrics\": [\"accuracy\"]},\n        \"tooluse\": {\"type\": \"tool_use\", \"metrics\": [\"success_rate\"]},\n        \"api_bank\": {\"type\": \"api_call\", \"metrics\": [\"accuracy\"]}\n    }\n    \n    async def run_benchmark(\n        self,\n        agent: BaseAgent,\n        benchmark: str\n    ) -> Dict:\n        \"\"\"Run specific benchmark\"\"\"\n        if benchmark not in self.BENCHMARKS:\n            raise ValueError(f\"Unknown benchmark: {benchmark}\")\n        \n        test_cases = self.load_benchmark(benchmark)\n        evaluator = AgentEvaluator()\n        \n        results = await evaluator.evaluate(agent, test_cases)\n        \n        return {\n            \"benchmark\": benchmark,\n            **results\n        }\n```\n\n-----\n\n## Multi-Agent Systems\n\n### Agent Collaboration\n\n```python\nclass MultiAgentOrchestrator:\n    \"\"\"Orchestrates multiple specialized agents\"\"\"\n    \n    def __init__(self):\n        self.agents: Dict[str, BaseAgent] = {}\n        self.task_queue: asyncio.Queue = asyncio.Queue()\n    \n    def register_agent(self, name: str, agent: BaseAgent, capabilities: List[str]):\n        \"\"\"Register an agent with capabilities\"\"\"\n        self.agents[name] = {\n            \"agent\": agent,\n            \"capabilities\": capabilities,\n            \"busy\": False\n        }\n    \n    async def assign_task(self, task: str) -> Dict:\n        \"\"\"Assign task to best available agent\"\"\"\n        # Analyze task requirements\n        required = self.analyze_requirements(task)\n        \n        # Find suitable agent\n        agent_info = self.select_agent(required)\n        \n        if not agent_info:\n            return {\"status\": \"no_agent\", \"task\": task}\n        \n        # Execute task\n        agent = agent_info[\"agent\"]\n        result = await agent.run(task)\n        \n        return {\n            \"status\": \"completed\",\n            \"agent\": agent_info[\"name\"],\n            \"result\": result\n        }\n    \n    def analyze_requirements(self, task: str) -> List[str]:\n        \"\"\"Analyze task to determine requirements\"\"\"\n        # Simplified - would use LLM\n        keywords = {\n            \"search\": [\"search\", \"find\", \"look up\"],\n            \"code\": [\"code\", \"implement\", \"program\"],\n            \"write\": [\"write\", \"create\", \"draft\"]\n        }\n        \n        required = []\n        for capability, patterns in keywords.items():\n            if any(p in task.lower() for p in patterns):\n                required.append(capability)\n        \n        return required\n    \n    def select_agent(self, requirements: List[str]) -> Optional[Dict]:\n        \"\"\"Select agent based on requirements\"\"\"\n        for name, info in self.agents.items():\n            caps = set(info[\"capabilities\"])\n            reqs = set(requirements)\n            \n            if reqs.issubset(caps) and not info[\"busy\"]:\n                info[\"busy\"] = True\n                return {\"name\": name, **info}\n        \n        return None\n```\n\n### Debate and Consensus\n\n```python\nclass DebateOrchestrator:\n    \"\"\"Multi-agent debate system\"\"\"\n    \n    def __init__(self, num_agents: int = 3):\n        self.agents = [BaseAgent(config) for _ in range(num_agents)]\n        self.max_rounds = 3\n    \n    async def debate(self, topic: str) -> Dict:\n        \"\"\"Run debate on topic\"\"\"\n        # Initial statements\n        statements = []\n        for agent in self.agents:\n            statement = await agent.run(f\"Provide your position on: {topic}\")\n            statements.append(statement)\n        \n        # Debate rounds\n        for round in range(self.max_rounds):\n            # Each agent responds to others\n            responses = []\n            for i, agent in enumerate(self.agents):\n                other_statements = [s for j, s in enumerate(statements) if j != i]\n                response = await agent.run(\n                    f\"Debate topic: {topic}\\n\\n\"\n                    f\"Other positions:\\n\" + \"\\n\".join(other_statements)\n                )\n                statements[i] = response\n                responses.append(response)\n        \n        # Reach consensus or summarize\n        consensus = await self.find_consensus(statements)\n        \n        return {\n            \"statements\": statements,\n            \"consensus\": consensus,\n            \"rounds\": self.max_rounds\n        }\n```\n\n-----\n\n## Best Practices\n\n1. **Start Simple** — Begin with basic agents before adding complexity.\n\n2. **Tool Design Matters** — Design tools with clear, specific purposes and well-defined schemas.\n\n3. **Handle Failures Gracefully** — Implement retry logic and fallback strategies.\n\n4. **Monitor and Log** — Track agent decisions for debugging and improvement.\n\n5. **Evaluate Continuously** — Benchmark agents on realistic test cases.\n\n6. **Guardrails Are Essential** — Implement safety measures for autonomous actions.\n\n7. **Memory Management** — Balance context retention with token efficiency.\n\n8. **Plan for Scale** — Consider multi-agent architectures for complex tasks.\n",{"name":5,"license":15,"metadata":48,"description":54,"compatibility":33},{"tags":49,"audience":52,"category":53},[5,27,50,51],"ai-agents","llm-agents","ml-engineers, developers","artificial-intelligence","Expert guidance on agentic AI systems, autonomous agents, and AI orchestration. Use for:  building agentic AI systems, tool orchestration, memory systems, planning and reasoning,  multi-step workflows, feedback loops, evaluation frameworks, ReAct patterns, and building  sophisticated AI pipelines.\n","main","2ea764e153842704d24a2e9aa4170441a7f03081",".opencode\u002Fskills\u002Fagentic-ai","https:\u002F\u002Fgithub.com\u002FNeuralBlitz\u002FMito","https:\u002F\u002Fgithub.com\u002FNeuralBlitz","nuralnexus.org","Independent Multidisciplinary Researcher, Creative Producer, and AI Systems Architect\r\nAn independent creator and research-driven systems designer.","2026-11-12 03:13:05",{"source":8,"skillName":5,"commands":64,"prompt":74,"zipAvailable":75},[65,68,71],{"tool":66,"command":67},"npx","npx skills add NeuralBlitz\u002FMito --skill agentic-ai",{"tool":69,"command":70},"bunx","bunx skills add NeuralBlitz\u002FMito --skill agentic-ai",{"tool":72,"command":73},"pnpm","pnpm dlx skills add NeuralBlitz\u002FMito --skill agentic-ai","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FNeuralBlitz\u002FMito\u002Fblob\u002Fmain\u002F.opencode\u002Fskills\u002Fagentic-ai\u002FSKILL.md",true,[],[78,94,107,120,128,151],{"skillNo":79,"name":80,"nameZh":6,"description":81,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":82,"categories":83,"keywords":84,"publishedAt":43},"01M6HAZSAQK1S27CEZYAYJTQDX","wireless-communications","Wireless systems, mobile networks, and 5G\u002F6G","https:\u002F\u002Fgithub.com\u002FNeuralBlitz\u002FMito\u002Fblob\u002Fmain\u002F.opencode\u002Fskills\u002Fwireless-communications\u002FSKILL.md",[],[85,86,87,88,89,90,91,92,33,93],"communications","wireless communications","wireless","systems","engineering","networks","5G","students","mobile",{"skillNo":95,"name":96,"nameZh":6,"description":97,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":98,"categories":99,"keywords":100,"publishedAt":43},"01M6HAZFX6E8NK3WZWDX5YCKYY","websockets","WebSocket implementation and best practices","https:\u002F\u002Fgithub.com\u002FNeuralBlitz\u002FMito\u002Fblob\u002Fmain\u002F.opencode\u002Fskills\u002Fwebassembly\u002Fwebsockets\u002FSKILL.md",[],[96,101,102,103,33,104,105,106],"websocket implementation","time","implementation","real-time","websocket","best practices",{"skillNo":108,"name":109,"nameZh":6,"description":110,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":111,"categories":112,"keywords":113,"publishedAt":43},"01M6HAZ6DAXBQ7QHXXM1EM7715","vulnerability-auditing","Vulnerability assessment and auditing","https:\u002F\u002Fgithub.com\u002FNeuralBlitz\u002FMito\u002Fblob\u002Fmain\u002F.opencode\u002Fskills\u002Fvulnerability-auditing\u002FSKILL.md",[],[114,115,116,117,33,118,119],"vulnerability","vulnerability auditing","security","vulnerability assessment","cybersecurity","assessment",{"skillNo":121,"name":122,"nameZh":6,"description":123,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":124,"categories":125,"keywords":126,"publishedAt":43},"01M6HAZ3FKF3CS9Z3J96RVE2ZE","vulnerability-assessment","Finding and assessing security vulnerabilities","https:\u002F\u002Fgithub.com\u002FNeuralBlitz\u002FMito\u002Fblob\u002Fmain\u002F.opencode\u002Fskills\u002Fvue\u002Fvulnerability-assessment\u002FSKILL.md",[],[117,114,119,116,127,33],"vulnerabilities",{"skillNo":129,"name":130,"nameZh":6,"description":131,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":132,"categories":133,"keywords":142,"publishedAt":43},"01M6HAYSHM6HKRKEHFP0SGZQX7","vlsi-design","Very-Large-Scale Integration circuit design and semiconductor engineering","https:\u002F\u002Fgithub.com\u002FNeuralBlitz\u002FMito\u002Fblob\u002Fmain\u002F.opencode\u002Fskills\u002Fvlsi-design\u002FSKILL.md",[134,137],{"categoryNo":135,"categoryName":136,"taxonomyType":21,"taxonomyTypeDesc":22},"01JBSEEDCAT000000000000015","视觉设计",{"categoryNo":138,"categoryName":139,"taxonomyType":140,"taxonomyTypeDesc":141},"01JBSEEDCAT000000000000032","设计师","PROFESSION","适用职业",[143,144,145,146,147,89,148,33,149,92,150],"vlsi design","VLSI","design","hardware","integration","computer","scale","circuit",{"skillNo":152,"name":153,"nameZh":6,"description":154,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":155,"categories":156,"keywords":157,"publishedAt":43},"01M6HAYPQ30FFE2JXD7WQJ8R6C","unsupervised","Unsupervised learning concepts","https:\u002F\u002Fgithub.com\u002FNeuralBlitz\u002FMito\u002Fblob\u002Fmain\u002F.opencode\u002Fskills\u002Fvisualization\u002Funsupervised\u002FSKILL.md",[],[153,158,33,29,159,160,161,162],"learning","unsupervised learning","machine","concepts","machine-learning"]