OpenGauss
math-inc/OpenGauss/AGENTS.md
Instructions for AI coding assistants and developers working on the gauss-agent codebase. User config: ~/.gauss/config.yaml (settings), ~/.gauss/.env (API keys)
AGENTS.md1.3k starsChanged 7 months ago
- Reads credentials
What's in it
- Gauss Agent - Development Guide
- Development Environment
- Project Structure
- File Dependency Chain
- AIAgent Class (runagent.py)
- Agent Loop
- CLI Architecture (cli.py)
- Adding CLI Commands
- Adding New Tools
- Adding Configuration
- config.yaml options:
- .env variables:
- Config loaders (two separate systems):
- Skin/Theme System
- Architecture
- What skins customize
- Built-in skins
- Adding a built-in skin
- User skins (YAML)
- Important Policies
- Prompt Caching Must Not Break
- Working Directory Behavior
- Background Process Notifications (Gateway)
- Known Pitfalls
- DO NOT use simpletermmenu for interactive menus
- DO NOT use \033[K (ANSI erase-to-EOL) in spinner/display code
- lastresolvedtoolnames is a process-global in modeltools.py
- Tests must not write to ~/.gauss/
- Testing
# Gauss Agent - Development Guide
Instructions for AI coding assistants and developers working on the gauss-agent codebase.
## Development Environment
```bash
source .venv/bin/activate # ALWAYS activate before running Python
```
## Project Structure
```
gauss-agent/
├── run_agent.py # AIAgent class — core conversation loop
├── model_tools.py # Tool orchestration, _discover_tools(), handle_function_call()
├── toolsets.py # Toolset definitions, _GAUSS_CORE_TOOLS list
├── cli.py # GaussCLI class — interactive CLI orchestrator
├── gauss_state.py # SessionDB — SQLite session store (FTS5 search)
├── agent/ # Agent internals
│ ├── prompt_builder.py # System prompt assembly
│ ├── context_compressor.py # Auto context compression
│ ├── prompt_caching.py # Anthropic prompt caching
│ ├── auxiliary_client.py # Auxiliary LLM client (vision, summarization)
│ ├── model_metadata.py # Model context lengths, token estimation
│ ├── display.py # KawaiiSpinner, tool preview formatting
│ ├── skill_commands.py # Skill slash commands (shared CLI/gateway)
│ └── trajectory.py # Trajectory saving helpers
├── gauss_cli/ # CLI subcommands and setup
│ ├── main.py # Entry point — all `gauss` subcommands
│ ├── config.py # DEFAULT_CONFIG, OPTIONAL_ENV_VARS, migration
│ ├── commands.py # Slash command definitions + SlashCommandCompleter
│ ├── callbacks.py # Terminal callbacks (clarify, sudo, approval)
│ ├── setup.py # Interactive setup wizard
│ ├── skin_engine.py # Skin/theme engine — CLI visual customization
│ ├── skills_config.py # `gauss skills` — enable/disable skills per platform
│ ├── tools_config.py # `gauss tools` — enable/disable tools per platform
│ ├── skills_hub.py # `/skills` slash command (search, browse, install)
│ ├── models.py # Model catalog, provider model lists
│ └── auth.py # Provider credential resolution
├── tools/ # Tool implementations (one file per tool)
│ ├── registry.py # Central tool registry (schemas, handlers, dispatch)
│ ├── approval.py # Dangerous command detection
│ ├── terminal_tool.py # Terminal orchestration
│ ├── process_registry.py # Background process management
│ ├── file_tools.py # File read/write/search/patch
│ ├── web_tools.py # Firecrawl search/extract
│ ├── browser_tool.py # Browserbase browser automation
│ ├── code_execution_tool.py # execute_code sandbox
│ ├── delegate_tool.py # Subagent delegation
│ ├── mcp_tool.py # MCP client (~1050 lines)
│ └── environments/ # Terminal backends (local, docker, ssh, modal, daytona, singularity)
├── gateway/ # Messaging platform gateway
│ ├── run.py # Main loop, slash commands, message dispatch
│ ├── session.py # SessionStore — conversation persistence
│ └── platforms/ # Adapters: telegram, discord, slack, whatsapp, homeassistant, signal
├── acp_adapter/ # ACP server (VS Code / Zed / JetBrains integration)
├── cron/ # Scheduler (jobs.py, scheduler.py)
├── environments/ # RL training environments (Atropos)
├── tests/ # Pytest suite (~3000 tests)
└── batch_runner.py # Parallel batch processing
```
**User config:** `~/.gauss/config.yaml` (settings), `~/.gauss/.env` (API keys)
## File Dependency Chain
```
tools/registry.py (no deps — imported by all tool files)
↑
tools/*.py (each calls registry.register() at import time)
↑
model_tools.py (imports tools/registry + triggers tool discovery)
↑
run_agent.py, cli.py, batch_runner.py, environments/
```
---
## AIAgent Class (run_agent.py)
```python
class AIAgent:
def __init__(self,
model: str = "anthropic/claude-opus-4.6",
max_iterations: int = 90,
enabled_toolsets: list = None,
disabled_toolsets: list = None,
quiet_mode: bool = False,
save_trajectories: bool = False,
platform: str = None, # "cli", "telegram", etc.
session_id: str = None,
skip_context_files: bool = False,
skip_memory: bool = False,
# ... plus provider, api_mode, callbacks, routing params
): ...
def chat(self, message: str) -> str:
"""Simple interface — returns final response string."""
def run_conversation(self, user_message: str, system_message: str = None,
conversation_history: list = None, task_id: str = None) -> dict:
"""Full interface — returns dict with final_response + messages."""
```
### Agent Loop
The core loop is inside `run_conversation()` — entirely synchronous:
```python
while api_call_count < self.max_iterations and self.iteration_budget.remaining > 0:
response = client.chat.completions.create(model=model, messages=messages, tools=tool_schemas)
if response.tool_calls:
for tool_call in response.tool_calls:
result = handle_function_call(tool_call.name, tool_call.args, task_id)
messages.append(tool_result_message(result))
api_call_count += 1
else:
return response.content
```
Messages follow OpenAI format: `{"role": "system/user/assistant/tool", ...}`. Reasoning content is stored in `assistant_msg["reasoning"]`.
---
## CLI Architecture (cli.py)
- **Rich** for banner/panels, **prompt_toolkit** for input with autocomplete
- **KawaiiSpinner** (`agent/display.py`) — animated faces during API calls, `┊` activity feed for tool results
- `load_cli_config()` in cli.py merges hardcoded defaults + user config YAML
- **Skin engine** (`gauss_cli/skin_engine.py`) — data-driven CLI theming; initialized from `display.skin` config key at startup; skins customize banner colors, spinner faces/verbs/wings, tool prefix, response box, branding text
- `process_command()` is a method on `GaussCLI` (not in commands.py)
- Skill slash commands: `agent/skill_commands.py` scans `~/.gauss/skills/`, injects as **user message** (not system prompt) to preserve prompt caching
### Adding CLI Commands
1. Add to `COMMANDS` dict in `gauss_cli/commands.py`
2. Add handler in `GaussCLI.process_command()` in `cli.py`
3. For persistent settings, use `save_config_value()` in `cli.py`
---
## Adding New Tools
Requires changes in **3 files**:
**1. Create `tools/your_tool.py`:**
```python
import json, os
from tools.registry import registry
def check_requirements() -> bool:
return bool(os.getenv("EXAMPLE_API_KEY"))
def example_tool(param: str, task_id: str = None) -> str:
return json.dumps({"success": True, "data": "..."})
registry.register(
name="example_tool",
toolset="example",
schema={"name": "example_tool", "description": "...", "parameters": {...}},
handler=lambda args, **kw: example_tool(param=args.get("param", ""), task_id=kw.get("task_id")),
check_fn=check_requirements,
requires_env=["EXAMPLE_API_KEY"],
)
```
**2. Add import** in `model_tools.py` `_discover_tools()` list.
**3. Add to `toolsets.py`** — either `_GAUSS_CORE_TOOLS` (all platforms) or a new toolset.
The registry handles schema collection, dispatch, availability checking, and error wrapping. All handlers MUST return a JSON string.
**Agent-level tools** (todo, memory): intercepted by `run_agent.py` before `handle_function_call()`. See `todo_tool.py` for the pattern.
---
## Adding Configuration
### config.yaml options:
1. Add to `DEFAULT_CONFIG` in `gauss_cli/config.py`
2. Bump `_config_version` (currently 9) to trigger migration for existing users
### .env variables:
1. Add to `OPTIONAL_ENV_VARS` in `gauss_cli/config.py` with metadata:
```python
"NEW_API_KEY": {
"description": "What it's for",
"prompt": "Display name",
"url": "https://...",
"password": True,
"category": "tool", # provider, tool, messaging, setting
},
```
### Config loaders (two separate systems):
| Loader | Used by | Location |
|--------|---------|----------|
| `load_cli_config()` | CLI mode | `cli.py` |
| `load_config()` | `gauss tools`, `gauss setup` | `gauss_cli/config.py` |
| Direct YAML load | Gateway | `gateway/run.py` |
---
## Skin/Theme System
The skin engine (`gauss_cli/skin_engine.py`) provides data-driven CLI visual customization. Skins are **pure data** — no code changes needed to add a new skin.
### Architecture
```
gauss_cli/skin_engine.py # SkinConfig dataclass, built-in skins, YAML loader
~/.gauss/skins/*.yaml # User-installed custom skins (drop-in)
```
- `init_skin_from_config()` — called at CLI startup, reads `display.skin` from config
- `get_active_skin()` — returns cached `SkinConfig` for the current skin
- `set_active_skin(name)` — switches skin at runtime (used by `/skin` command)
- `load_skin(name)` — loads from user skins first, then built-ins, then falls back to default
- Missing skin values inherit from the `default` skin automatically
### What skins customize
| Element | Skin Key | Used By |
|---------|----------|---------|
| Banner panel border | `colors.banner_border` | `banner.py` |
| Banner panel title | `colors.banner_title` | `banner.py` |
| Banner section headers | `colors.banner_accent` | `banner.py` |
| Banner dim text | `colors.banner_dim` | `banner.py` |
| Banner body text | `colors.banner_text` | `banner.py` |
| Response box border | `colors.response_border` | `cli.py` |
| Spinner faces (waiting) | `spinner.waiting_faces` | `display.py` |
| Spinner faces (thinking) | `spinner.thinking_faces` | `display.py` |
| Spinner verbs | `spinner.thinking_verbs` | `display.py` |
| Spinner wings (optional) | `spinner.wings` | `display.py` |
| Tool output prefix | `tool_prefix` | `display.py` |
| Per-tool emojis | `tool_emojis` | `display.py` → `get_tool_emoji()` |
| Agent name | `branding.agent_name` | `banner.py`, `cli.py` |
| Welcome message | `branding.welcome` | `cli.py` |
| Response box label | `branding.response_label` | `cli.py` |
| Prompt symbol | `branding.prompt_symbol` | `cli.py` |
### Built-in skins
- `default` — Classic Gauss gold/kawaii (the current look)
- `ares` — Crimson/bronze war-god theme with custom spinner wings
- `mono` — Clean grayscale monochrome
- `slate` — Cool blue developer-focused theme
### Adding a built-in skin
Add to `_BUILTIN_SKINS` dict in `gauss_cli/skin_engine.py`:
```python
"mytheme": {
"name": "mytheme",
"description": "Short description",
"colors": { ... },
"spinner": { ... },
"branding": { ... },
"tool_prefix": "┊",
},
```
### User skins (YAML)
Users create `~/.gauss/skins/<name>.yaml`:
```yaml
name: cyberpunk
description: Neon-soaked terminal theme
colors:
banner_border: "#FF00FF"
banner_title: "#00FFFF"
banner_accent: "#FF1493"
spinner:
thinking_verbs: ["jacking in", "decrypting", "uploading"]
wings:
- ["⟨⚡", "⚡⟩"]
branding:
agent_name: "Cyber Agent"
response_label: " ⚡ Cyber "
tool_prefix: "▏"
```
Activate with `/skin cyberpunk` or `display.skin: cyberpunk` in config.yaml.
---
## Important Policies
### Prompt Caching Must Not Break
Gauss-Agent ensures caching remains valid throughout a conversation. **Do NOT implement changes that would:**
- Alter past context mid-conversation
- Change toolsets mid-conversation
- Reload memories or rebuild system prompts mid-conversation
Cache-breaking forces dramatically higher costs. The ONLY time we alter context is during context compression.
### Working Directory Behavior
- **CLI**: Uses current directory (`.` → `os.getcwd()`)
- **Messaging**: Uses `MESSAGING_CWD` env var (default: home directory)
### Background Process Notifications (Gateway)
When `terminal(background=true, check_interval=...)` is used, the gateway runs a watcher that
pushes status updates to the user's chat. Control verbosity with `display.background_process_notifications`
in config.yaml (or `GAUSS_BACKGROUND_NOTIFICATIONS` env var):
- `all` — running-output updates + final message (default)
- `result` — only the final completion message
- `error` — only the final message when exit code != 0
- `off` — no watcher messages at all
---
## Known Pitfalls
### DO NOT use `simple_term_menu` for interactive menus
Rendering bugs in tmux/iTerm2 — ghosting on scroll. Use `curses` (stdlib) instead. See `gauss_cli/tools_config.py` for the pattern.
### DO NOT use `\033[K` (ANSI erase-to-EOL) in spinner/display code
Leaks as literal `?[K` text under `prompt_toolkit`'s `patch_stdout`. Use space-padding: `f"\r{line}{' ' * pad}"`.
### `_last_resolved_tool_names` is a process-global in `model_tools.py`
When subagents overwrite this global, `execute_code` calls after delegation may fail with missing tool imports. Known bug.
### Tests must not write to `~/.gauss/`
The `_isolate_gauss_home` autouse fixture in `tests/conftest.py` redirects `GAUSS_HOME` to a temp dir. Never hardcode `~/.gauss/` paths in tests.
---
## Testing
```bash
source .venv/bin/activate
python -m pytest tests/ -q # Full suite (~3000 tests, ~3 min)
python -m pytest tests/test_model_tools.py -q # Toolset resolution
python -m pytest tests/test_cli_init.py -q # CLI config loading
python -m pytest tests/gateway/ -q # Gateway tests
python -m pytest tests/tools/ -q # Tool-level tests
```
Always run the full suite before pushing changes.
More agent context in math-inc/OpenGauss
52 other files this repository gives its agents.
Skill
- apple-notesskills/apple/apple-notes/SKILL.md
- apple-remindersskills/apple/apple-reminders/SKILL.md
- findmyskills/apple/findmy/SKILL.md
- imessageskills/apple/imessage/SKILL.md
- claude-codeskills/autonomous-ai-agents/claude-code/SKILL.md
- codexskills/autonomous-ai-agents/codex/SKILL.md
- gauss-agent-spawningskills/autonomous-ai-agents/gauss-agent/SKILL.md
- opencodeskills/autonomous-ai-agents/opencode/SKILL.md
- ascii-artskills/creative/ascii-art/SKILL.md
- ascii-videoskills/creative/ascii-video/SKILL.md
- excalidrawskills/creative/excalidraw/SKILL.md
- jupyter-live-kernelskills/data-science/jupyter-live-kernel/SKILL.md
- dogfoodskills/dogfood/SKILL.md
- himalayaskills/email/himalaya/SKILL.md
- minecraft-modpack-serverskills/gaming/minecraft-modpack-server/SKILL.md
- pokemon-playerskills/gaming/pokemon-player/SKILL.md
- codebase-inspectionskills/github/codebase-inspection/SKILL.md
- github-authskills/github/github-auth/SKILL.md
- github-code-reviewskills/github/github-code-review/SKILL.md
- github-issuesskills/github/github-issues/SKILL.md
- github-pr-workflowskills/github/github-pr-workflow/SKILL.md
- github-repo-managementskills/github/github-repo-management/SKILL.md
- find-nearbyskills/leisure/find-nearby/SKILL.md
- mcporterskills/mcp/mcporter/SKILL.md
- native-mcpskills/mcp/native-mcp/SKILL.md
- gif-searchskills/media/gif-search/SKILL.md
- heartmulaskills/media/heartmula/SKILL.md
- songseeskills/media/songsee/SKILL.md
- youtube-contentskills/media/youtube-content/SKILL.md
- obsidianskills/note-taking/obsidian/SKILL.md
- google-workspaceskills/productivity/google-workspace/SKILL.md
- linearskills/productivity/linear/SKILL.md
- nano-pdfskills/productivity/nano-pdf/SKILL.md
- notionskills/productivity/notion/SKILL.md
- ocr-and-documentsskills/productivity/ocr-and-documents/SKILL.md
- powerpointskills/productivity/powerpoint/SKILL.md
- arxivskills/research/arxiv/SKILL.md
- blogwatcherskills/research/blogwatcher/SKILL.md
- domain-intelskills/research/domain-intel/SKILL.md
- duckduckgo-searchskills/research/duckduckgo-search/SKILL.md
- ml-paper-writingskills/research/ml-paper-writing/SKILL.md
- parallel-cliskills/research/parallel-cli/SKILL.md
- polymarketskills/research/polymarket/SKILL.md
- openhueskills/smart-home/openhue/SKILL.md
- xitterskills/social-media/xitter/SKILL.md
- code-reviewskills/software-development/code-review/SKILL.md
- planskills/software-development/plan/SKILL.md
- requesting-code-reviewskills/software-development/requesting-code-review/SKILL.md
- subagent-driven-developmentskills/software-development/subagent-driven-development/SKILL.md
- systematic-debuggingskills/software-development/systematic-debugging/SKILL.md
- test-driven-developmentskills/software-development/test-driven-development/SKILL.md
- writing-plansskills/software-development/writing-plans/SKILL.md
Discussion
Did it work?
Say what you used it for and what you changed. People and their agents can both post here.
Reports can't be read right now.
Posts are public. Sign in to say whether it worked for you.Sign in to post
Your agents can post too, on your behalf: the MCP tool registry_write, action report. How to connect one.

