mirror of
https://github.com/google/adk-docs.git
synced 2026-09-14 16:16:59 +08:00
7458d68a64
* #1029 - 8 vector_store_similarity_search and SpannerVectorStoreSettings Added vector_store_similarity_search to SpannerToolset. SpannerVectorStoreSettings is introduced to support this feature. * Update spanner.md * Update spanner.md Applied feedback. Additionally, reviewed the phrasing in the intro for clarity and concision and did some minor formatting edits. * Fix wrapping, missing import, trailing whitespace, formatting fixes * Restructure Spanner page: add intro, section headings, reorder vector search * Add experimental tags/notes to corresponding integration pages --------- Co-authored-by: Kristopher Overholt <koverholt@google.com>
68 lines
3.8 KiB
Markdown
68 lines
3.8 KiB
Markdown
---
|
|
catalog_title: Pub/Sub Tools
|
|
catalog_description: Publish, pull, and acknowledge messages from Google Cloud Pub/Sub
|
|
catalog_icon: /integrations/assets/pubsub.png
|
|
catalog_tags: ["google"]
|
|
---
|
|
|
|
# Google Cloud Pub/Sub tool for ADK
|
|
|
|
<div class="language-support-tag">
|
|
<span class="lst-supported">Supported in ADK</span><span class="lst-python">Python v1.22.0</span><span class="lst-preview">Experimental</span>
|
|
</div>
|
|
|
|
The `PubSubToolset` allows agents to interact with
|
|
[Google Cloud Pub/Sub](https://cloud.google.com/pubsub)
|
|
service to publish, pull, and acknowledge messages.
|
|
|
|
!!! example "Experimental"
|
|
This feature is experimental and may be updated in future releases.
|
|
|
|
## Prerequisites
|
|
|
|
Before using the `PubSubToolset`, you need to:
|
|
|
|
1. **Enable the Pub/Sub API** in your Google Cloud project.
|
|
2. **Authenticate and authorize**: Ensure that the principal (e.g., user, service account) running the agent has the necessary IAM permissions to perform Pub/Sub operations. For more information on Pub/Sub roles, see the [Pub/Sub access control documentation](https://cloud.google.com/pubsub/docs/access-control).
|
|
3. **Create a topic or subscription**: [Create a topic](https://cloud.google.com/pubsub/docs/create-topic) to publish messages and [create a subscription](https://cloud.google.com/pubsub/docs/create-subscription) to receive them.
|
|
|
|
|
|
## Usage
|
|
|
|
```py
|
|
--8<-- "examples/python/snippets/tools/built-in-tools/pubsub.py"
|
|
```
|
|
## Tools
|
|
|
|
The `PubSubToolset` includes the following tools:
|
|
|
|
### `publish_message`
|
|
|
|
Publishes a message to a Pub/Sub topic.
|
|
|
|
| Parameter | Type | Description |
|
|
| -------------- | ------------------- | ------------------------------------------------------------------------------------------------------- |
|
|
| `topic_name` | `str` | The name of the Pub/Sub topic (e.g., `projects/my-project/topics/my-topic`). |
|
|
| `message` | `str` | The message content to publish. |
|
|
| `attributes` | `dict[str, str]` | (Optional) Attributes to attach to the message. |
|
|
| `ordering_key` | `str` | (Optional) The ordering key for the message. If you set this parameter, messages are published in order. |
|
|
|
|
### `pull_messages`
|
|
|
|
Pulls messages from a Pub/Sub subscription.
|
|
|
|
| Parameter | Type | Description |
|
|
| ------------------- | ------- | ----------------------------------------------------------------------------------------------------------- |
|
|
| `subscription_name` | `str` | The name of the Pub/Sub subscription (e.g., `projects/my-project/subscriptions/my-sub`). |
|
|
| `max_messages` | `int` | (Optional) The maximum number of messages to pull. Defaults to `1`. |
|
|
| `auto_ack` | `bool` | (Optional) Whether to automatically acknowledge the messages. Defaults to `False`. |
|
|
|
|
### `acknowledge_messages`
|
|
|
|
Acknowledges one or more messages on a Pub/Sub subscription.
|
|
|
|
| Parameter | Type | Description |
|
|
| ------------------- | ------------- | ------------------------------------------------------------------------------------------------- |
|
|
| `subscription_name` | `str` | The name of the Pub/Sub subscription (e.g., `projects/my-project/subscriptions/my-sub`). |
|
|
| `ack_ids` | `list[str]` | A list of acknowledgment IDs to acknowledge. |
|