Guidance for agents working in this repository.
This is a Rust workspace with the ai crate in crates/ai and example
packages under examples/.
The crate provides:
- LLM streaming and one-shot completion APIs.
- Tool calling and JSON Schema based tool definitions.
- Model lookup and custom model configuration.
- OAuth helpers for Anthropic and GitHub Copilot.
- A lightweight agent loop with events, tool execution, steering, and follow-up queues.
The root README.md is intentionally short. The detailed crate documentation
lives in crates/ai/README.md.
Prefer the mise tasks:
mise run fmt
mise run check
mise run clippy
mise run test-ai
mise run test
mise run allEquivalent cargo commands:
cargo fmt --all --check
cargo check --workspace --all-targets
cargo clippy --workspace --all-targets -- -D warnings
cargo test -p ai
cargo test --workspaceUse stream_simple for streaming responses and complete_simple for one-shot
responses unless the lower-level StreamOptions shape is needed. Use stream
or complete for direct provider-option forwarding or lower-level request
control.
The active built-in language provider scope is OpenAI, Anthropic, and GitHub
Copilot. The active built-in image provider scope is OpenAI-compatible image
generation and OpenRouter image generation. Azure Foundry and other compatible
language endpoints should be documented and tested as configured provider
handles, such as providers::openai::builder() plus
provider.model(...).base_url(...).headers(...).compat(...).
Do not add broad provider autodetection by provider name or base URL unless that
provider is intentionally in scope.
- Use semantic/conventional commit messages, such as
feat: add provider,fix: handle stream errors,docs: update README, orchore: update lockfile. - When porting behavior from the original Pi TypeScript implementation to Rust, treat Pi as the source of truth and keep the port as close to 1:1 as Rust permits. Preserve Pi's behavior, control flow, data model, helper boundaries, and naming where possible; make only mechanical adaptations required by the language or this crate's existing public API. Do not add downstream consumer- specific behavior to the port. Document any unavoidable semantic divergence from Pi explicitly.
- Use the same semantic/conventional style for PR titles, such as
feat: add provider,fix(example): limit bash tool execution, orci: run clippy in workflow. PR bodies should include conciseSummaryandVerificationsections. - Keep public behavior aligned with the existing Rust API shape before adding new abstractions.
- Add or update tests for provider payload changes, stream event ordering, tool-call behavior, abort behavior, and agent loop state changes.
- The tests currently live mostly as module-level unit tests under
crates/ai/src; there is nocrates/ai/testsdirectory at the moment. - Avoid unrelated README policy sections, logos, or copied upstream text.