<span id="发现与选择智能体"></span>

# Discover and Select Agents

Query visible agent catalog cards in the current workspace, check each entry's object kind, status, and available actions, and record the agent ID and source workspace ID needed for downstream calls.

(sdk-ai-studio-agents-flow)=
<span id="任务流程"></span>

## Task flow

```text
Workspace client
       │
       ▼
Page through agent catalog cards
       │
       ▼
Check kind (agent), status, and actions
       │
       ▼
Save agent ID and source workspace ID
```

(sdk-ai-studio-agents-prepare)=
<span id="准备"></span>

## Prerequisites

1. Complete the endpoint, personal access token, and workspace setup in [Use the SDK](../../../quickstart/ai-studio/sdk.md).

(sdk-ai-studio-agents-s1)=
<span id="查询智能体目录卡片"></span>

## Query agent catalog cards

Run the example below to fetch up to 20 catalog cards in the current workspace and print each entry's kind, source workspace ID, agent ID, name, status, and available actions. Pass an `offset` query option to read subsequent pages until you reach `total` or receive an empty page.

:::::{tab-set}
:sync-group: sdk-language

::::{tab-item} Python
:sync: python

```python
import os

import moi_product_sdk as sdk

client = sdk.new_with_personal_access_token(
    os.environ["PRODUCT_API_BASE_URL"],
    os.environ["PRODUCT_API_KEY"],
)
workspace_id = os.environ["WORKSPACE_ID"]
page = client.agents(workspace_id).list_agent_catalog_cards(
    sdk.with_query_param("limit", "20"),
    sdk.with_query_param("offset", "0"),
)
print("total:", page.total, "limit:", page.limit, "offset:", page.offset)
for card in page.items:
    print(
        card.kind,
        card.workspace_id,
        card.id,
        card.name,
        card.status,
        list(card.actions),
    )
```

::::

::::{tab-item} Go
:sync: go

```go
package main

import (
	"context"
	"fmt"
	"log"
	"os"

	sdk "github.com/matrixorigin/matrixflow/sdk/go-sdk"
)

func main() {
	client, err := sdk.NewWithPersonalAccessToken(
		os.Getenv("PRODUCT_API_BASE_URL"),
		os.Getenv("PRODUCT_API_KEY"),
	)
	if err != nil {
		log.Fatal(err)
	}
	defer client.Close()

	page, err := client.Agents(os.Getenv("WORKSPACE_ID")).ListAgentCatalogCards(
		context.Background(),
		sdk.WithQueryParam("limit", "20"),
		sdk.WithQueryParam("offset", "0"),
	)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println("total:", page.GetTotal(), "limit:", page.GetLimit(), "offset:", page.GetOffset())
	for _, card := range page.GetItems() {
		fmt.Println(
			card.GetKind(),
			card.GetWorkspaceId(),
			card.GetId(),
			card.GetName(),
			card.GetStatus(),
			card.GetActions(),
		)
	}
}
```

::::

:::::

The catalog can include both individual agents (`agent`) and teams, as well as system-provided entries. For single-agent invocation and version maintenance, choose an entry whose `kind` is `agent` and record both its `id` and `workspace_id`.

(sdk-ai-studio-agents-next)=
<span id="下一步"></span>

## Next steps

- [Invoke Agents and Track Tasks](调用智能体并跟踪任务.md#sdk-ai-studio-agent-task-send)
- [Manage Agent Versions](查看和切换智能体版本.md#sdk-ai-studio-agent-version-list)
- [Connect Messaging Channels](连接消息通道.md)
