Skip to main content

Custom agents

Custom agents let you split responsibilities by role and run sub-agents for specific tasks. In Laravel, configure them with SessionConfig customAgents. For orchestrating multiple sub-agents in parallel, see Fleet Mode.

Basic usage

You can also pass it as an array config.

Configuration fields

Write concrete description values to improve auto-selection accuracy.

Per-agent declarative hooks

In a custom agent’s hooks, you can specify event names as keys and arrays of declarative actions as values. The actions are passed to the CLI together with that agent’s definition and apply only to that agent. Use this when, for example, you want to restrict tool execution for a specific agent only.
customAgents[*].hooks are declarative actions passed to the CLI. Specify the actions in the format accepted by Copilot CLI.
  • The top-level hooks in SessionConfig is a separate feature that registers PHP callbacks and applies to the whole session. See Session hooks for details.
  • Loading file-based hooks from .github/hooks/ is controlled separately with enableFileHooks.

Start a session with a specific agent

Set agent to activate one custom agent from the first turn.

Disable auto-selection with infer: false

For high-risk agents, disable automatic selection and require explicit use.

Hide tools from the default agent

Use defaultAgent.excludedTools to hide specific tools from only the default agent. This makes delegation to a custom agent easier.

Observe sub-agent events

subagent.* events are emitted while sub-agents run. You can observe them with onEvent or $session->on().

Best practices

  • Separate researcher (read-heavy) and editor (change-heavy).
  • Keep tools minimal and least-privileged.
  • Make description concrete to improve delegation.
  • Handle subagent.failed with retry or fallback strategy.
Last modified on October 19, 2026