Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion go/cli/internal/cli/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,15 @@ func printTools(tools []database.Tool) error {

func printAgents(agents []api.AgentResponse) error {
// Prepare table data
headers := []string{"#", "NAME", "CREATED"}
headers := []string{"#", "NAME", "CREATED", "DEPLOYMENT_READY", "ACCEPTED"}
rows := make([][]string, len(agents))
for i, agent := range agents {
rows[i] = []string{
strconv.Itoa(i + 1),
utils.GetObjectRef(agent.Agent),
agent.Agent.CreationTimestamp.Format(time.RFC3339),
strconv.FormatBool(agent.DeploymentReady),
strconv.FormatBool(agent.Accepted),
}
}

Expand Down
18 changes: 13 additions & 5 deletions go/internal/httpserver/handlers/agents.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,9 @@ func (h *AgentsHandler) HandleListAgents(w ErrorResponseWriter, r *http.Request)
agentRef := common.GetObjectRef(&agent)
log.V(1).Info("Processing Agent", "agentRef", agentRef)

agentResponse, err := h.getAgentResponse(r.Context(), log, &agent)
if err != nil {
w.RespondWithError(err)
return
}
// When listing agents, we don't want a failure when a single agent has an issue, so we ignore the error.
// The getAgentResponse should return its reconciliation status in the agentResponse.
agentResponse, _ := h.getAgentResponse(r.Context(), log, &agent)

agentsWithID = append(agentsWithID, agentResponse)
}
Expand All @@ -75,10 +73,20 @@ func (h *AgentsHandler) getAgentResponse(ctx context.Context, log logr.Logger, a
}
}

accepted := false
for _, condition := range agent.Status.Conditions {
// The exact reason is not important (although "AgentReconciled" is the current one), as long as the agent is accepted
if condition.Type == "Accepted" && condition.Status == "True" {
accepted = true
break
}
}

response := api.AgentResponse{
ID: common.ConvertToPythonIdentifier(agentRef),
Agent: agent,
DeploymentReady: deploymentReady,
Accepted: accepted,
}

if agent.Spec.Type == v1alpha2.AgentType_Declarative {
Expand Down
65 changes: 64 additions & 1 deletion go/internal/httpserver/handlers/agents_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func TestHandleGetAgent(t *testing.T) {
require.False(t, response.Data.DeploymentReady) // No status conditions, should be false
})

t.Run("gets agent with DeploymentReady=true", func(t *testing.T) {
t.Run("gets agent with DeploymentReady=true, Accepted=true", func(t *testing.T) {
modelConfig := createTestModelConfig()
conditions := []metav1.Condition{
{
Expand Down Expand Up @@ -150,6 +150,7 @@ func TestHandleGetAgent(t *testing.T) {
err := json.Unmarshal(w.Body.Bytes(), &response)
require.NoError(t, err)
require.True(t, response.Data.DeploymentReady)
require.True(t, response.Data.Accepted)
})

t.Run("gets agent with DeploymentReady=false when Ready status is False", func(t *testing.T) {
Expand Down Expand Up @@ -235,6 +236,11 @@ func TestHandleListAgents(t *testing.T) {
Status: "True",
Reason: "DeploymentReady",
},
{
Type: "Accepted",
Status: "True",
Reason: "AgentReconciled",
},
}
readyAgent := createTestAgentWithStatus("ready-agent", modelConfig, readyConditions)

Expand Down Expand Up @@ -269,6 +275,63 @@ func TestHandleListAgents(t *testing.T) {
require.Equal(t, v1alpha2.ModelProviderOpenAI, response.Data[1].ModelProvider)
require.Equal(t, true, response.Data[1].DeploymentReady)
})

t.Run("lists expected agent conditions", func(t *testing.T) {
modelConfig := createTestModelConfig()

// Agent with DeploymentReady=true
readyConditions := []metav1.Condition{
{
Type: "Ready",
Status: "True",
Reason: "DeploymentReady",
},
{
Type: "Accepted",
Status: "True",
Reason: "AgentReconciled",
},
}
invalidConditions := []metav1.Condition{ // an agent's deployment can be ready although it's configuration is invalid
{
Type: "Accepted",
Status: "False",
Reason: "AgentReconcileFailed",
},
{
Type: "Ready",
Status: "True",
Reason: "DeploymentReady",
},
}
readyAgent := createTestAgentWithStatus("ready-agent", modelConfig, readyConditions)
invalidAgent := createTestAgentWithStatus("invalid-agent", modelConfig, invalidConditions)

handler, _ := setupTestHandler(readyAgent, invalidAgent, modelConfig)
createAgent(handler.DatabaseService, readyAgent)
createAgent(handler.DatabaseService, invalidAgent)

req := httptest.NewRequest("GET", "/api/agents", nil)
req = setUser(req, "test-user")

w := httptest.NewRecorder()

handler.HandleListAgents(&testErrorResponseWriter{w}, req)

require.Equal(t, http.StatusOK, w.Code)

// both agents are returned with their statuses
var response api.StandardResponse[[]api.AgentResponse]
err := json.Unmarshal(w.Body.Bytes(), &response)
require.NoError(t, err)
require.Len(t, response.Data, 2)
require.Equal(t, "ready-agent", response.Data[1].Agent.Name)
require.Equal(t, true, response.Data[1].Accepted)
require.Equal(t, true, response.Data[1].DeploymentReady)
require.Equal(t, "invalid-agent", response.Data[0].Agent.Name)
require.Equal(t, false, response.Data[0].Accepted)
require.Equal(t, true, response.Data[0].DeploymentReady)
})
}

func TestHandleUpdateAgent(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions go/pkg/client/api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ type AgentResponse struct {
MemoryRefs []string `json:"memoryRefs"`
Tools []*v1alpha2.Tool `json:"tools"`
DeploymentReady bool `json:"deploymentReady"`
Accepted bool `json:"accepted"`
}

// Session types
Expand Down
17 changes: 11 additions & 6 deletions ui/src/components/AgentCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ interface AgentCardProps {
id: number;
}

export function AgentCard({ id, agentResponse: { agent, model, modelProvider, deploymentReady } }: AgentCardProps) {
export function AgentCard({ id, agentResponse: { agent, model, modelProvider, deploymentReady, accepted } }: AgentCardProps) {
const router = useRouter();
const agentRef = k8sRefUtils.toRef(
agent.metadata.namespace || '',
Expand All @@ -29,34 +29,39 @@ export function AgentCard({ id, agentResponse: { agent, model, modelProvider, de

const cardContent = (
<Card className={`group transition-colors ${
deploymentReady
deploymentReady && accepted
? 'cursor-pointer hover:border-violet-500'
: 'cursor-not-allowed opacity-60 border-gray-300'
}`}>
<CardHeader className="flex flex-row items-start justify-between space-y-0 pb-2">
<CardTitle className="flex items-center gap-2">
<KagentLogo className="h-5 w-5" />
{agentRef}
{!accepted && (
<span className="text-xs bg-red-100 text-red-800 px-2 py-1 rounded-full">
Not Accepted
</span>
)}
{!deploymentReady && (
<span className="text-xs bg-yellow-100 text-yellow-800 px-2 py-1 rounded-full">
Not Ready
</span>
)}
</CardTitle>
<div className={`flex items-center space-x-2 ${deploymentReady ? 'invisible group-hover:visible' : 'invisible'}`}>
<div className={`flex items-center space-x-2 ${deploymentReady && accepted ? 'invisible group-hover:visible' : 'invisible'}`}>
<Button
variant="ghost"
size="icon"
onClick={handleEditClick}
aria-label="Edit Agent"
disabled={!deploymentReady}
disabled={!deploymentReady || !accepted}
>
<Pencil className="h-4 w-4" />
</Button>
<DeleteButton
agentName={agent.metadata.name}
namespace={agent.metadata.namespace || ''}
disabled={!deploymentReady}
disabled={!deploymentReady || !accepted}
/>
</div>
</CardHeader>
Expand All @@ -73,7 +78,7 @@ export function AgentCard({ id, agentResponse: { agent, model, modelProvider, de
</Card>
);

return deploymentReady ? (
return deploymentReady && accepted ? (
<Link href={`/agents/${agent.metadata.namespace}/${agent.metadata.name}/chat`} passHref>
{cardContent}
</Link>
Expand Down
19 changes: 11 additions & 8 deletions ui/src/components/sidebars/AgentSwitcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,21 @@ export function AgentSwitcher({ currentAgent, allAgents }: AgentSwitcherProps) {
const router = useRouter();
const { isMobile } = useSidebar();

const selectedTeam = currentAgent;
const selectedAgent = currentAgent;
const agentResponses = allAgents;

if (!selectedTeam) {
if (!selectedAgent) {
return null;
}

const selectedTeamRef = k8sRefUtils.toRef(
selectedTeam.agent.metadata.namespace || "",
selectedTeam.agent.metadata.name
const selectedAgentRef = k8sRefUtils.toRef(
selectedAgent.agent.metadata.namespace || "",
selectedAgent.agent.metadata.name
);

// We don't want to show agents that are not ready or accepted
const filteredAgentResponses = agentResponses.filter(({ deploymentReady, accepted }) => deploymentReady && accepted);

return (
<SidebarMenu>
<SidebarMenuItem>
Expand All @@ -41,15 +44,15 @@ export function AgentSwitcher({ currentAgent, allAgents }: AgentSwitcherProps) {
<KagentLogo className="w-4 h-4" />
</div>
<div className="grid flex-1 text-left text-sm leading-tight">
<span className="truncate font-semibold">{selectedTeamRef}</span>
<span className="truncate text-xs">{selectedTeam.modelProvider} ({selectedTeam.model})</span>
<span className="truncate font-semibold">{selectedAgentRef}</span>
<span className="truncate text-xs">{selectedAgent.modelProvider} ({selectedAgent.model})</span>
</div>
<ChevronsUpDown className="ml-auto" />
</SidebarMenuButton>
</DropdownMenuTrigger>
<DropdownMenuContent className="w-[--radix-dropdown-menu-trigger-width] min-w-56 rounded-lg" align="start" side={isMobile ? "bottom" : "right"} sideOffset={4}>
<DropdownMenuLabel className="text-xs text-muted-foreground">Agents</DropdownMenuLabel>
{agentResponses.map(({ id, agent}, index) => {
{filteredAgentResponses.map(({ id, agent }, index) => {
const agentRef = k8sRefUtils.toRef(agent.metadata.namespace || "", agent.metadata.name)
return (
<DropdownMenuItem
Expand Down
1 change: 1 addition & 0 deletions ui/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ export interface AgentResponse {
memoryRefs: string[];
tools: Tool[];
deploymentReady: boolean;
accepted: boolean;
}

export interface RemoteMCPServer {
Expand Down
Loading