This guide covers development workflows, code quality tools, and CI/CD setup for AgentObs.
# Install dependencies
mix deps.get
# Run pre-commit checks
mix precommit
# Run CI checks
mix ciAgentObs uses Elixir's built-in formatter:
# Format all files
mix format
# Check if files are formatted (CI)
mix format --check-formattedConfiguration is in .formatter.exs.
Static code analysis for code quality and consistency:
# Run Credo
mix credo
# Run in strict mode (recommended for CI)
mix credo --strict
# Explain a specific issue
mix credo explain lib/agent_obs.ex:104Configuration is in .credo.exs. Current settings:
- Max line length: 120 characters
- Module documentation required
- Strict consistency checks enabled
- TODOs allowed (warning only)
Static type analysis using Dialyzer:
# Run Dialyzer (first run will be slow while building PLT)
mix dialyzer
# Clean PLT cache
rm -rf priv/plts/PLT files are cached in priv/plts/ and excluded from git.
Recommended to run before committing code:
- Formats code - Auto-fixes formatting
- Runs tests - Ensures all tests pass
- Runs Credo - Checks code quality in strict mode
Exit status: Fails if tests fail or Credo finds issues.
Designed for continuous integration pipelines:
- Checks formatting - Fails if code is not formatted
- Runs tests - Ensures all tests pass
- Runs Credo - Checks code quality in strict mode
Exit status: Fails if any check fails.
# Run all tests
mix test
# Run with coverage
mix test --cover
# Run specific test file
mix test test/agent_obs_test.exs
# Run specific test
mix test test/agent_obs_test.exs:10
# Run tests matching a pattern
mix test --only agenttest/
├── test_helper.exs # Test configuration
├── agent_obs_test.exs # Core API tests
└── agent_obs/
├── events_test.exs # Event schema tests
└── handlers/
└── phoenix/
└── translator_test.exs # OpenInference translation tests
The project includes a comprehensive CI workflow in .github/workflows/ci.yml:
Tests run on multiple Elixir and OTP versions:
- Elixir: 1.14, 1.15, 1.16, 1.17, 1.18
- OTP: 25.0, 26.0, 27.0
- Invalid combinations are excluded
-
Test Job
- Runs on each Elixir/OTP combination
- Checks formatting
- Runs full test suite
- Runs Credo in strict mode
- Uses dependency and build caching
-
Dialyzer Job
- Runs on latest Elixir/OTP only
- Caches PLT files for faster runs
- Performs static type analysis
- Modules: PascalCase (
AgentObs.Handlers.Phoenix) - Functions: snake_case (
trace_agent/3) - Variables: snake_case (
start_metadata) - Atoms: snake_case (
:agent_obs)
All public modules and functions must have:
@moduledocwith description and examples@docfor each public function@spectype specifications
Example:
@doc """
Instruments an agent loop.
## Examples
AgentObs.trace_agent("my_agent", %{input: "task"}, fn ->
{:ok, "result"}
end)
"""
@spec trace_agent(String.t(), map(), function()) :: term()
def trace_agent(name, metadata, fun) do
# ...
endPrefer pattern matching in function heads:
# Good
def normalize_message(%{role: role} = message) when is_atom(role) do
%{message | role: to_string(role)}
end
# Avoid
def normalize_message(message) do
if is_atom(message.role) do
%{message | role: to_string(message.role)}
end
endUse tagged tuples for error handling:
{:ok, result} | {:error, reason}Use with for sequential validation:
with :ok <- validate_field(data, :name),
:ok <- validate_field(data, :input) do
{:ok, data}
endTo automatically run checks before commits:
# Create a git pre-commit hook
cat > .git/hooks/pre-commit << 'HOOK'
#!/bin/sh
mix precommit
HOOK
chmod +x .git/hooks/pre-commit# Clean build artifacts
mix clean
# Re-fetch dependencies
mix deps.clean --all
mix deps.get
# Run tests again
mix test# Clean PLT cache
rm -rf priv/plts/
# Rebuild PLT
mix dialyzer# Auto-fix formatting
mix format
# Verify
mix format --check-formatted- Update version in
mix.exs - Update
CHANGELOG.mdwith changes - Run
mix precommitto ensure quality - Commit changes
- Tag release:
git tag v0.1.0 - Push:
git push && git push --tags - Publish to Hex:
mix hex.publish
- Mix tasks:
mix help - Credo:
mix credo --help - Dialyzer:
mix dialyzer --help - Tests:
mix help test