feat(#735): Agent-first architecture — CLI, abilities, runtime, and Admin UI#763
Merged
feat(#735): Agent-first architecture — CLI, abilities, runtime, and Admin UI#763
Conversation
Add AgentResolver for --agent=<slug|id> resolution, parallel to UserResolver. Agent scoping takes precedence over --user when both are provided. Updated commands: - PipelinesCommand: --agent scoping for list/get - FlowsCommand: --agent scoping for list/get - JobsCommand: --agent scoping for list - MemoryCommand: --agent scoping for read/write/search/sections/daily/files AgentResolver.buildScopingInput() provides the bridge: resolves --agent first, falls back to --user, returns empty for unscoped. 9 new tests for AgentResolver. All 805 tests pass, lint clean.
Add full agent lifecycle management to CLI and Abilities: CLI commands (wp datamachine agents): - create <slug> --name --owner --config: create new agent with owner access - show <slug|id>: display agent details, config, access grants - delete <slug|id> [--delete-files]: remove agent and access grants - access grant/revoke/list: manage agent RBAC (admin/operator/viewer) AgentAbilities additions: - createAgent(): creates agent, bootstraps owner access, ensures directory - getAgent(): retrieves agent with config, access grants, directory info - deleteAgent(): removes agent, access grants, optional file cleanup Handles json_decode safely when DB layer pre-decodes agent_config. 13 new tests covering all CRUD operations. All 818 tests pass.
Homeboy Results —
|
Add agent_id to input schemas and execution logic for: - CreatePipelineAbility: stores agent_id, cascades to auto-created flows - CreateFlowAbility: stores agent_id in DB when provided - DuplicatePipelineAbility: carries agent_id from source or allows override - AgentMemoryAbilities: all 4 schemas now document agent_id alongside user_id The DB layer already accepts agent_id — these changes close the gap between the CLI (PR #763) and the abilities/REST layer so callers can scope resources to agents end-to-end. 15 new tests verify schema registration and DB propagation.
Add agent_id to ExecutionContext (new private property) and EngineData: - ExecutionContext::fromFlow() accepts optional agent_id parameter - ExecutionContext::fromConfig() extracts agent_id from config array - ExecutionContext::getAgentId() returns explicit agent_id or falls back to engine data's job context - ExecutionContext::log() includes agent_id in log context when present - EngineData::getAgentId() reads from job snapshot's agent_id field - withHandlerType/withJobId preserve agent_id through clone Agent identity now flows end-to-end: flow DB → job creation → engine snapshot → ExecutionContext → handlers + logging. 12 new tests verify all factory methods, fallbacks, and clone behavior.
… gap Chat sessions were the only Admin UI page bypassing agent filtering. The list endpoint, ability, DB layer, and client-side query now all support agent_id so the AgentSwitcher filters chat sessions like it already does for pipelines, flows, jobs, and logs. - DB: get_user_sessions() and get_user_session_count() accept optional agent_id - ListChatSessionsAbility: agent_id in input schema, passed to DB - REST /chat/sessions: agent_id route arg, resolved via PermissionHelper - chat.js: useChatSessions() switched from raw apiFetch to shared client so the agent interceptor auto-injects agent_id on every list request
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements the agent-first architecture (#735) — making
agent_idthe primary scoping key across CLI, abilities, runtime, and Admin UI. All 5 logical PRs are on this branch.Key discovery: The DB schema, REST scoping, and most Admin UI agent filtering were already built. This PR fills the remaining gaps to make
agent_ida first-class citizen everywhere.Commits
1.
--agentflag across all CLI commandsAgentResolverclass:resolve(),resolveContext(),buildScopingInput()--agentfor agent-scoped queries2. Agent CRUD CLI + abilities
agents create/show/delete+agents access grant/revoke/listCLI subcommandsAgentAbilities:createAgent(),getAgent(),deleteAgent()with full validation3. Agent context propagation in abilities
CreatePipelineAbility:agent_idin schema, stored in DB, cascaded to auto-created flowsCreateFlowAbility:agent_idin schema, stored in DBDuplicatePipelineAbility: carriesagent_idfrom source, allows override, cascades to flowsAgentMemoryAbilities: all 4 schemas documentagent_id4. ExecutionContext carries agent identity
ExecutionContext:$agent_idproperty,getAgentId()with engine data fallbackfromFlow()/fromConfig()extract agent_id;log()includes it in contextEngineData::getAgentId()reads from job snapshotwithHandlerType()/withJobId()preserve agent_id through clone5. Chat sessions agent scoping (last Admin UI gap)
get_user_sessions()andget_user_session_count()accept optionalagent_idListChatSessionsAbility:agent_idin input schema, passed through to DB/chat/sessions:agent_idroute arg, resolved viaPermissionHelper::resolve_scoped_agent_id()chat.js:useChatSessions()switched from rawapiFetchto sharedclientso the agent interceptor auto-injectsagent_idTest results
845 tests, 0 failures (27 new tests added across PRs 1-4)
Files changed
New files
inc/Cli/AgentResolver.phptests/Unit/Cli/AgentResolverTest.phptests/Unit/Abilities/AgentAbilitiesTest.phptests/Unit/Abilities/AgentContextPropagationTest.phptests/Unit/Core/ExecutionContextAgentTest.phpModified
inc/Cli/Commands/PipelinesCommand.phpinc/Cli/Commands/Flows/FlowsCommand.phpinc/Cli/Commands/JobsCommand.phpinc/Cli/Commands/MemoryCommand.phpinc/Cli/Commands/AgentsCommand.phpinc/Abilities/AgentAbilities.phpinc/Abilities/AgentMemoryAbilities.phpinc/Abilities/Pipeline/CreatePipelineAbility.phpinc/Abilities/Pipeline/DuplicatePipelineAbility.phpinc/Abilities/Flow/CreateFlowAbility.phpinc/Abilities/Chat/ListChatSessionsAbility.phpinc/Api/Chat/Chat.phpinc/Core/ExecutionContext.phpinc/Core/EngineData.phpinc/Core/Database/Chat/Chat.phpinc/Core/Admin/Pages/Pipelines/assets/react/queries/chat.jsCloses #735