Removed sections that duplicate Workspace Memory: - Recommended Entry Points (Memory has precise file/line locations) - For Debugging paths (Memory has session/error log details) - Dependency Analysis Artifacts (reference info, not actionable) Kept essential guardrails: - Critical Invariants (MUST/MUST NOT rules) - Dangerous Code Paths (risk warnings, not locations) - Do/Dont coding standards - Common Incorrect Assumptions Reduction: 125 lines → 69 lines (~45% smaller, ~650 tokens saved)
3.1 KiB
3.1 KiB
AGENTS.md - Machine Instructions for g3
Purpose: Machine-specific instructions for AI agents working with this codebase.
For code locations: See Workspace Memory (loaded automatically)
For project overview: See README.md
Critical Invariants
MUST Hold
- Tool calls must be valid JSON - The streaming parser expects well-formed tool calls
- Context window limits must be respected - Exceeding limits causes API errors
- Provider trait implementations must be Send + Sync - Required for async runtime
- Session IDs must be unique - Used for log file paths and TODO scoping
- File paths in tools support tilde expansion -
~expands to home directory - Streaming is preferred - Non-streaming requests block UI
- Tool results are size-limited - Large outputs are truncated or thinned automatically
- String slicing must be UTF-8 safe - Use
chars().take(n)orchar_indices(), never byte slicing like&s[..n]on user-facing strings
MUST NOT Do
- Never block the async runtime - Use
tokio::spawnfor CPU-intensive work - Never store secrets in logs - API keys are redacted in error logs
- Never modify files outside working directory without explicit permission
- Never assume tool results fit in context - Large results are thinned automatically
- Never use byte-index string slicing on text with potential multi-byte characters - Causes panics on emoji, CJK, box-drawing chars
Adding Features
- New tool: Add definition in
tool_definitions.rs, implement intools/, add dispatch case - New provider: Implement
LLMProvidertrait ing3-providers - New CLI mode: Add to CLI args, implement handler in
g3-cli - New config option: Add to
g3-configstructs
Dangerous Code Paths
These areas have subtle bugs if modified incorrectly:
| Area | Risk |
|---|---|
| Context window management | Incorrect token estimates cause context overflow |
| Streaming parser | Partial JSON across chunks causes parsing failures |
| Tool dispatch | Missing dispatch cases cause silent failures |
| Retry logic | Aggressive retries hit rate limits harder |
| Parser sanitization | Inline JSON can trigger false tool call detection |
Do's and Don'ts
Do
- ✅ Run
cargo checkafter modifications - ✅ Run
cargo testbefore committing - ✅ Update tool definitions when adding tools
- ✅ Add tests for new functionality
- ✅ Keep functions under 80 lines
Don't
- ❌ Add blocking code in async contexts
- ❌ Store sensitive data in plain text
- ❌ Ignore error handling
- ❌ Create deeply nested conditionals (>6 levels)
- ❌ Add external dependencies for simple tasks
Common Incorrect Assumptions
- "All providers support tool calling" - Embedded models use JSON fallback
- "Context window is unlimited" - Each provider has limits (4k-200k tokens)
- "Tool results are always small" - File reads can return megabytes
- "Sessions persist across runs" - Sessions are ephemeral by default
- "All platforms are equal" - macOS has more features (Vision, Accessibility)