clawchain/x/agent/keeper/query_agent_tasks.go
caelum0x db831658ab feat(agent): expand gRPC surface, tasks, intents, negotiations, IBC discovery
Adds full QueryServer/MsgServer gRPC services, task lifecycle handlers
(accept, checkpoint, complete, delegate), intent protocol, negotiation
system, IBC agent discovery, rate limiting, reputation adapter, and
comprehensive test coverage.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-16 22:13:45 +03:00

51 lines
1.3 KiB
Go

package keeper
import (
"context"
"clawchain/x/agent/types"
)
// QueryAgentTasks returns all tasks currently assigned to a specific agent address.
// This is used by the crash-recovery system to check on-chain task state after a restart.
func (k Keeper) QueryAgentTasks(ctx context.Context, agentAddr string) ([]types.TaskRecord, error) {
if agentAddr == "" {
return nil, nil
}
var tasks []types.TaskRecord
err := k.Tasks.Walk(ctx, nil, func(_ uint64, task types.TaskRecord) (bool, error) {
if task.AssigneeAddress == agentAddr {
tasks = append(tasks, task)
}
return false, nil
})
if err != nil {
return nil, err
}
return tasks, nil
}
// QueryAgentActiveTasks returns only active (pending or accepted) tasks assigned
// to the given agent address. This is the primary entry point for recovery: it
// tells the runtime which tasks are still live on-chain.
func (k Keeper) QueryAgentActiveTasks(ctx context.Context, agentAddr string) ([]types.TaskRecord, error) {
if agentAddr == "" {
return nil, nil
}
var tasks []types.TaskRecord
err := k.Tasks.Walk(ctx, nil, func(_ uint64, task types.TaskRecord) (bool, error) {
if task.AssigneeAddress == agentAddr && (task.Status == "pending" || task.Status == "accepted") {
tasks = append(tasks, task)
}
return false, nil
})
if err != nil {
return nil, err
}
return tasks, nil
}