adachsoft / ai-agent-run-contracts
Contracts and immutable models for recording AI agent runs, events, and usage statistics.
Package info
gitlab.com/a.adach/ai-agent-run-contracts
pkg:composer/adachsoft/ai-agent-run-contracts
Requires
- php: ^8.3
- adachsoft/ai-agent: ^0.14
- adachsoft/collection: ^3.0
Requires (Dev)
- adachsoft/php-code-style: ^0.8.0
- friendsofphp/php-cs-fixer: ^3.95
- phpstan/phpstan: ^2.3
- phpunit/phpunit: ^13
- rector/rector: ^2.9
- symplify/phpstan-rules: ^14.19
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Contracts for recorded AI agent runs built on adachsoft/ai-agent. This library defines the shared model and extension points that applications and persistence or execution adapters can use to record and coordinate agent runs.
- Model:
AgentRun(immutable, validated status transitionsqueued → running → done|failed|cancelled),AgentEvent+AgentEventTypeEnum(tool calls, model responses, run lifecycle),AgentUsageStats. AgentRef: agent id + optional, application-definedscope(for example a project id).- Repository interfaces: runs, run events (append-only, ordered by
seq), per-agent usage statistics. ConversationLockInterface(one active run per conversation),AgentRunDispatcherInterface(background execution).- SPI implemented by the application:
Spi\AgentFacadeProviderInterface– creates the agent facade for anAgentRefand conversation,Spi\ActiveConversationResolverInterface– active conversation id (for tools that switch conversations).
Implementations: adachsoft/ai-agent-run-repository-json (storage), adachsoft/ai-agent-run-lib (services).
Contract tests: adachsoft/ai-agent-run-contract-tests.
Installation
composer require adachsoft/ai-agent-run-contracts
Integration
Use the immutable run and event models in your application services, and implement the repository, lock, dispatcher, and SPI interfaces in the application or an infrastructure adapter. Inject those implementations into the services that coordinate run creation and execution. Persist events in sequence order and use the conversation lock to prevent concurrent active runs for the same conversation.
See the examples for a run lifecycle example.
Requirements
- PHP 8.3 or later.
- Composer for dependency installation and autoloading.
adachsoft/ai-agentfor applications that provide the agent facade integration.
Usage
Create a queued run when work is accepted, then use the immutable transition methods as execution progresses:
$run = AgentRun::queue($runId, $scope, $agentId, $conversationId, $prompt, $createdAt);
$runningRun = $run->markRunning($startedAt);
$completedRun = $runningRun->markDone($finishedAt, $finalText, $tokens);
Store runs and ordered events through the repository interfaces. Implement the lock, dispatcher, and SPI interfaces at your application's infrastructure boundary, then inject those implementations into the coordinating services.