SDK for building composable AI agents in PHP.
This package provides:
AgentLoopfor step-based agent execution- tools and tool execution runtime
- hooks/guards for lifecycle control
AgentBuildercapabilities for composition- templates and session runtime for persisted workflows
This package is a split from the Instructor PHP monorepo.
composer require cognesy/agentsuse Cognesy\Agents\AgentLoop;
use Cognesy\Agents\Data\AgentState;
$agent = AgentLoop::default();
$state = AgentState::empty()->withUserMessage('What is 2+2?');
$result = $agent->execute($state);
echo $result->finalResponse()->toString();UseCodingTools installs the provider-familiar read, bash, edit, and
write tool names. UseSystemPrompt derives matching operating guidance from
the tools resolved into the built agent.
use Cognesy\Agents\Builder\AgentBuilder;
use Cognesy\Agents\Capability\Coding\UseCodingTools;
use Cognesy\Agents\Capability\Prompt\UseSystemPrompt;
use Cognesy\Agents\Data\AgentState;
$workDir = '/path/to/project';
$agent = AgentBuilder::base()
->withCapability(new UseCodingTools($workDir))
->withCapability(new UseSystemPrompt(
preamble: 'You are an expert coding assistant.',
))
->build();
$state = AgentState::empty()
->withUserMessage('Inspect the project and make the requested change.');
$result = $agent->execute($state);The deprecated CodingAgentPrompt preserves its static 2.5 coding prompt for
compatibility. New agents should use UseSystemPrompt, which derives tool and
guideline sections from the tools installed on the built agent.
The file contracts are deliberately bounded and conservative:
readdefaults to a numbered 200-line/32 KiB window and returns an exact continuation hint. Agents can explicitly increaselimitandmax_byteswhen a larger window or complete file is justified.editstreams through the source and atomically commits only after exact match validation succeeds.writecreates a new file atomically, requires an existing parent directory, and refuses to replace different content.bashreturns at most a 32 KiB window and explains how to recover from larger output.
Legacy UseFileTools remains available with the existing read_file,
edit_file, and write_file names.
Use the Agents docs for actual usage and architecture details:
packages/agents/docs/01-introduction.mdpackages/agents/docs/02-basic-agent.mdpackages/agents/docs/05-tools.mdpackages/agents/docs/13-agent-builder.mdpackages/agents/docs/14-agent-templates.mdpackages/agents/docs/16-session-runtime.md