Search by

adachsoft / ai-agent-run-contracts

Arkadiusz Adach

Contracts and immutable models for recording AI agent runs, events, and usage statistics.

Package info

gitlab.com/a.adach/ai-agent-run-contracts

Issues

pkg:composer/adachsoft/ai-agent-run-contracts

Statistics

Installs: 8

Dependents: 1

Suggesters: 0

Stars: 0

v0.1.0 2026-11-30 14:13 UTC

This package is auto-updated.

Last update: 2026-11-30 13:13:54 UTC


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 transitions queued → running → done|failed|cancelled), AgentEvent + AgentEventTypeEnum (tool calls, model responses, run lifecycle), AgentUsageStats.
  • AgentRef: agent id + optional, application-defined scope (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 an AgentRef and 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-agent for 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.