generated from coulomb/repo-seed
feat(WP-0012): IHF Phase 11 — Advanced AI Federation
Some checks failed
Test / test (push) Has been cancelled
Some checks failed
Test / test (push) Has been cancelled
- Schema: AgentRegistration, ModelRoutingPolicy, AgentDelegation, CollectiveProposal, CollectiveProposalContribution, AiGovernancePolicy, AgentPerformanceRecord + ALTER TABLE agent_proposals (migration 1744156800; CHECK constraints on trust_level, status, consensus_status — GAAF compliant) - Bridge: scripts/llm_bridge.py (llm-connect subprocess seam) + Application/Helper/AgentBridge.hs (callBridge, callAgent, checkGovernancePolicy, jsonArrayTexts) - Routing: Application/Helper/ModelRouter.hs (resolveAgent, resolveAllAgents) + ModelRoutingPolicies CRUD - Registry: AgentRegistrations CRUD (Index/Show/New/Edit/Performance), DeactivateAgentAction, ComputeAgentPerformanceAction - Delegation: AgentDelegations controller + views, DelegateSubtaskAction with token budget enforcement at bridge call time - Collective: CollectiveProposals controller + views, CreateCollectiveProposalAction (fan-out → synthesis → consensus detection) - Governance: AiGovernancePolicies CRUD + ToggleAiGovernancePolicyAction; checkGovernancePolicy enforced at all 4 Phase 5 invocation points - Phase 5 wiring: replaced callClaudeApi in Widgets, DecisionRecords, RequirementCandidates with resolveAgent + callAgent + token tracking - llm-connect feature requests: ~/llm-connect/FEATURE_REQUESTS.md (FR-1 HTTP serve, FR-2 RoutingPolicy, FR-3 async, FR-4 BudgetTracker) - GAAF scorecard: 3.61 (up from 3.56); Functional 3.4→3.6, Extensions 3.8→3.9 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
74
Web/Controller/AgentDelegations.hs
Normal file
74
Web/Controller/AgentDelegations.hs
Normal file
@@ -0,0 +1,74 @@
|
||||
module Web.Controller.AgentDelegations where
|
||||
|
||||
-- IHF Phase 11 — Advanced AI Federation (IHUB-WP-0012 T06)
|
||||
|
||||
import Web.Controller.Prelude
|
||||
import Web.View.AgentDelegations.Index
|
||||
import Web.View.AgentDelegations.Show
|
||||
import Application.Helper.AgentBridge (callBridge, BridgeRequest(..))
|
||||
|
||||
instance Controller AgentDelegationsController where
|
||||
|
||||
action AgentDelegationsAction = do
|
||||
delegations <- query @AgentDelegation
|
||||
|> orderByDesc #createdAt
|
||||
|> fetch
|
||||
render IndexView { .. }
|
||||
|
||||
action ShowAgentDelegationAction { agentDelegationId } = do
|
||||
delegation <- fetch agentDelegationId
|
||||
delegatingAgent <- fetch delegation.delegatingAgentId
|
||||
receivingAgent <- fetch delegation.receivingAgentId
|
||||
mParentProposal <- case delegation.parentProposalId of
|
||||
Nothing -> pure Nothing
|
||||
Just pid -> fetchOneOrNothing pid
|
||||
render ShowView { .. }
|
||||
|
||||
action DelegateSubtaskAction { agentProposalId } = do
|
||||
proposal <- fetch agentProposalId
|
||||
receivingAgentId <- param @(Id AgentRegistration) "receivingAgentId"
|
||||
scope <- param @Text "scope"
|
||||
tokenBudget <- paramOrDefault @Int 1000 "tokenBudget"
|
||||
delegatingAgentId <- case proposal.agentRegistrationId of
|
||||
Just aid -> pure aid
|
||||
Nothing -> respondAndExit =<< renderNotFound
|
||||
|
||||
receivingAgent <- fetch receivingAgentId
|
||||
|
||||
delegation <- newRecord @AgentDelegation
|
||||
|> set #delegatingAgentId delegatingAgentId
|
||||
|> set #receivingAgentId receivingAgentId
|
||||
|> set #parentProposalId (Just agentProposalId)
|
||||
|> set #scope scope
|
||||
|> set #tokenBudget tokenBudget
|
||||
|> set #status "pending"
|
||||
|> createRecord
|
||||
|
||||
result <- liftIO $ callBridge BridgeRequest
|
||||
{ provider = receivingAgent.provider
|
||||
, model = receivingAgent.modelName
|
||||
, systemPrompt = receivingAgent.systemPrompt
|
||||
, prompt = scope
|
||||
, maxTokens = tokenBudget
|
||||
, temperature = 0.7
|
||||
}
|
||||
|
||||
now <- getCurrentTime
|
||||
case result of
|
||||
Left err -> do
|
||||
delegation
|
||||
|> set #status "failed"
|
||||
|> set #result (Just . A.toJSON $ A.object ["error" A..= err.errorMessage])
|
||||
|> set #completedAt (Just now)
|
||||
|> updateRecord
|
||||
setErrorMessage ("Delegation failed: " <> err.errorMessage)
|
||||
Right resp -> do
|
||||
delegation
|
||||
|> set #status "completed"
|
||||
|> set #tokensUsed (Just resp.tokensOut)
|
||||
|> set #result (Just . A.toJSON $ A.object ["content" A..= resp.content])
|
||||
|> set #completedAt (Just now)
|
||||
|> updateRecord
|
||||
setSuccessMessage "Subtask delegated successfully"
|
||||
|
||||
redirectTo ShowAgentDelegationAction { agentDelegationId = delegation.id }
|
||||
Reference in New Issue
Block a user