Agent Observatory Workflow & Extension Guide
This skill guides agents and engineers on how to safely build, modify, test, and enhance AI agent features within agentic-observatory/.
1. Branch-First Development
[!IMPORTANT]
CREATE A LOCAL BRANCH FIRST: Always start by creating a local branch from main:
git switch -c MishraShardendu22/main/<feature-name>
Never develop or modify agent code directly on main.
2. Adding a New Agent Tool
- Create or update a tool file under
agentic-observatory/data/tools/:from typing import Annotated, Any
from langchain_core.tools import tool
@tool
async def inspect_custom_metric(
metric_name: Annotated[str, "The name of the metric to query"],
days: Annotated[int, "Number of lookback days"] = 7,
) -> dict[str, Any]:
"""Query custom operational metrics from the database."""
# Perform database query or API call
return {"metric": metric_name, "value": 42}
- Export the tool in
agentic-observatory/data/tools/__init__.py.
- Add the tool to the
TOOLS list in agentic-observatory/agent/openrouter.py.
2. Tool-Calling RAG & Vector Knowledge Base
The AI Observatory operates as a Tool-Calling RAG Agent:
- Pre-turn Retrieval: Injects top relevance chunks into system context before iteration 1.
- Dynamic Tool Calling: The agent calls
hybrid_search_knowledge_base during reasoning loops for deep evidence gathering:# Inside agent/openrouter.py:
from data.tools import hybrid_search_knowledge_base
- Supported source filters:
['chat_message', 'execution_log', 'investigation', 'backup_result', 'backup_fix'].
- Combines Full-Text Search (tsvector), pgvector cosine similarity, and Reciprocal Rank Fusion (RRF).
3. Implementing Human-In-The-Loop (HITL) Actions
For sensitive actions (e.g., sending emails, applying hotfixes, modifying DB records):
- In
agentic-observatory/agent/openrouter.py, intercept the tool before execution:if tool_name == "send_report_email":
confirm_id = str(uuid.uuid4())
confirm_event = asyncio.Event()
active_confirmations[confirm_id] = confirm_event
yield json.dumps({
"type": "confirm_required",
"confirm_id": confirm_id,
"name": tool_name,
"args": tool_args,
})
# Wait up to 120s for user response via /chat/confirm
await asyncio.wait_for(confirm_event.wait(), timeout=120.0)
- Feed the user approval or rejection back to the LLM context.
4. Working with Multi-Key OpenRouter Failover
Always use agentic-observatory/utils/openrouter_keys.py:
get_openrouter_api_keys(): Returns all configured keys.
get_active_openrouter_key(): Returns the currently active working key.
rotate_openrouter_key(failed_key, reason): Advances to the next backup key when an error (401, 402, 429) occurs.
5. Comprehensive Agent Test Suites
Run the test suite commands:
# 1. Run all unit and integration tests across the system
make test
# 2. Run dedicated AI Agent & Tool-Calling RAG test suite
make test-agents
# 3. Direct execution of Agent tests
cd agentic-observatory && uv run python test_agent_suite.py
1---2name: agent-observatory-workflow3description: Step-by-step instructions for extending the Python AI Observatory agent: adding LangChain tools, Tool-Calling RAG workflows, enforcing Human-in-the-Loop approvals, multi-key OpenRouter failover, and pgvector embeddings.4---56# Agent Observatory Workflow & Extension Guide78This skill guides agents and engineers on how to safely build, modify, test, and enhance AI agent features within `agentic-observatory/`.910## 1. Branch-First Development1112> [!IMPORTANT]13> **CREATE A LOCAL BRANCH FIRST**: Always start by creating a local branch from `main`:14> ```bash15> git switch -c MishraShardendu22/main/<feature-name>16> ```17> Never develop or modify agent code directly on `main`.1819---2021## 2. Adding a New Agent Tool22231. Create or update a tool file under [`agentic-observatory/data/tools/`](file:///home/ms22/Coding_stuff/Personal-Projects/github-backup-automation-system/agentic-observatory/data/tools/):24 ```python25 from typing import Annotated, Any26 from langchain_core.tools import tool2728 @tool29 async def inspect_custom_metric(30 metric_name: Annotated[str, "The name of the metric to query"],31 days: Annotated[int, "Number of lookback days"] = 7,32 ) -> dict[str, Any]:33 """Query custom operational metrics from the database."""34 # Perform database query or API call35 return {"metric": metric_name, "value": 42}36 ```372. Export the tool in [`agentic-observatory/data/tools/__init__.py`](file:///home/ms22/Coding_stuff/Personal-Projects/github-backup-automation-system/agentic-observatory/data/tools/__init__.py).383. Add the tool to the `TOOLS` list in [`agentic-observatory/agent/openrouter.py`](file:///home/ms22/Coding_stuff/Personal-Projects/github-backup-automation-system/agentic-observatory/agent/openrouter.py).3940---4142## 2. Tool-Calling RAG & Vector Knowledge Base4344The AI Observatory operates as a **Tool-Calling RAG Agent**:451. **Pre-turn Retrieval**: Injects top relevance chunks into system context before iteration 1.462. **Dynamic Tool Calling**: The agent calls `hybrid_search_knowledge_base` during reasoning loops for deep evidence gathering:47 ```python48 # Inside agent/openrouter.py:49 from data.tools import hybrid_search_knowledge_base50 ```51 * Supported source filters: `['chat_message', 'execution_log', 'investigation', 'backup_result', 'backup_fix']`.52 * Combines Full-Text Search (tsvector), pgvector cosine similarity, and Reciprocal Rank Fusion (RRF).5354---5556## 3. Implementing Human-In-The-Loop (HITL) Actions5758For sensitive actions (e.g., sending emails, applying hotfixes, modifying DB records):591. In `agentic-observatory/agent/openrouter.py`, intercept the tool before execution:60 ```python61 if tool_name == "send_report_email":62 confirm_id = str(uuid.uuid4())63 confirm_event = asyncio.Event()64 active_confirmations[confirm_id] = confirm_event6566 yield json.dumps({67 "type": "confirm_required",68 "confirm_id": confirm_id,69 "name": tool_name,70 "args": tool_args,71 })72 # Wait up to 120s for user response via /chat/confirm73 await asyncio.wait_for(confirm_event.wait(), timeout=120.0)74 ```752. Feed the user approval or rejection back to the LLM context.7677---7879## 4. Working with Multi-Key OpenRouter Failover8081Always use [`agentic-observatory/utils/openrouter_keys.py`](file:///home/ms22/Coding_stuff/Personal-Projects/github-backup-automation-system/agentic-observatory/utils/openrouter_keys.py):82* `get_openrouter_api_keys()`: Returns all configured keys.83* `get_active_openrouter_key()`: Returns the currently active working key.84* `rotate_openrouter_key(failed_key, reason)`: Advances to the next backup key when an error (`401`, `402`, `429`) occurs.8586---8788## 5. Comprehensive Agent Test Suites8990Run the test suite commands:91```bash92# 1. Run all unit and integration tests across the system93make test9495# 2. Run dedicated AI Agent & Tool-Calling RAG test suite96make test-agents9798# 3. Direct execution of Agent tests99cd agentic-observatory && uv run python test_agent_suite.py100```