733 lines
48 KiB
Python
733 lines
48 KiB
Python
from __future__ import annotations
|
|
|
|
import base64
|
|
import json
|
|
import re
|
|
from pathlib import Path
|
|
from typing import Any
|
|
|
|
import httpx
|
|
from a2a_pack.deepagents import create_a2a_deep_agent
|
|
from langchain_core.messages import BaseMessage
|
|
from langchain_core.tools import StructuredTool
|
|
from pydantic import BaseModel, Field
|
|
|
|
from a2a_pack import (
|
|
A2AAgent,
|
|
ConsumerSetup,
|
|
ConsumerSetupField,
|
|
ConsumerSetupMissing,
|
|
EgressPolicy,
|
|
LLMProvisioning,
|
|
Pricing,
|
|
Resources,
|
|
RunContext,
|
|
skill,
|
|
)
|
|
|
|
|
|
DEFAULT_BASE_URL = "https://{index_host}"
|
|
OPERATIONS = json.loads("{\n \"cancel_bulk_import\": {\n \"base_url\": \"https://{index_host}\",\n \"base_url_field\": \"OPENAPI_BASE_URL\",\n \"description\": \"Cancel an import operation if it is not yet finished. It has no effect if the operation is already finished.\\n\\nFor guidance and examples, see [Import data](https://docs.pinecone.io/guides/index-data/import-data).\",\n \"destructive\": true,\n \"method\": \"DELETE\",\n \"operation_id\": \"cancel_bulk_import\",\n \"parameters\": [\n {\n \"description\": \"Unique identifier for the import operation.\",\n \"in\": \"path\",\n \"name\": \"id\",\n \"required\": true,\n \"schema\": {\n \"maxLength\": 1000,\n \"minLength\": 1,\n \"type\": \"string\"\n }\n }\n ],\n \"path\": \"/bulk/imports/{id}\",\n \"request_body\": null,\n \"security\": null,\n \"skill_name\": \"cancel_bulk_import\",\n \"source_index\": 1,\n \"source_openapi_url\": \"https://raw.githubusercontent.com/pinecone-io/pinecone-api/main/2025-04/db_data_2025-04.oas.yaml\",\n \"source_title\": \"Pinecone Data Plane API\",\n \"summary\": \"Cancel an import\",\n \"tags\": [\n \"Bulk Operations\"\n ]\n },\n \"delete_namespace\": {\n \"base_url\": \"https://{index_host}\",\n \"base_url_field\": \"OPENAPI_BASE_URL\",\n \"description\": \"Delete a namespace from a serverless index. Deleting a namespace is irreversible; all data in the namespace is permanently deleted.\\n\\nFor guidance and examples, see [Manage namespaces](https://docs.pinecone.io/guides/manage-data/manage-namespaces).\\n\\n**Note:** This operation is not supported for pod-based indexes.\",\n \"destructive\": true,\n \"method\": \"DELETE\",\n \"operation_id\": \"delete_namespace\",\n \"parameters\": [\n {\n \"description\": \"The namespace to delete\",\n \"in\": \"path\",\n \"name\": \"namespace\",\n \"required\": true,\n \"schema\": {\n \"type\": \"string\"\n }\n }\n ],\n \"path\": \"/namespaces/{namespace}\",\n \"request_body\": null,\n \"security\": null,\n \"skill_name\": \"delete_namespace\",\n \"source_index\": 1,\n \"source_openapi_url\": \"https://raw.githubusercontent.com/pinecone-io/pinecone-api/main/2025-04/db_data_2025-04.oas.yaml\",\n \"source_title\": \"Pinecone Data Plane API\",\n \"summary\": \"Delete a namespace\",\n \"tags\": [\n \"Namespace Operations\"\n ]\n },\n \"delete_vectors\": {\n \"base_url\": \"https://{index_host}\",\n \"base_url_field\": \"OPENAPI_BASE_URL\",\n \"description\": \"Delete vectors by id from a single namespace.\\n\\nFor guidance and examples, see [Delete data](https://docs.pinecone.io/guides/manage-data/delete-data).\",\n \"destructive\": true,\n \"method\": \"POST\",\n \"operation_id\": \"delete_vectors\",\n \"parameters\": [],\n \"path\": \"/vectors/delete\",\n \"request_body\": {\n \"$ref\": \"#/components/schemas/DeleteRequest\"\n },\n \"security\": null,\n \"skill_name\": \"delete_vectors\",\n \"source_index\": 1,\n \"source_openapi_url\": \"https://raw.githubusercontent.com/pinecone-io/pinecone-api/main/2025-04/db_data_2025-04.oas.yaml\",\n \"source_title\": \"Pinecone Data Plane API\",\n \"summary\": \"Delete vectors\",\n \"tags\": [\n \"Vector Operations\"\n ]\n },\n \"describe_bulk_import\": {\n \"base_url\": \"https://{index_host}\",\n \"base_url_field\": \"OPENAPI_BASE_URL\",\n \"description\": \"Return details of a specific import operation.\\n\\nFor guidance and examples, see [Import data](https://docs.pinecone.io/guides/index-data/import-data).\",\n \"destructive\": false,\n \"method\": \"GET\",\n \"operation_id\": \"describe_bulk_import\",\n \"parameters\": [\n {\n \"description\": \"Unique identifier for the import operation.\",\n \"in\": \"path\",\n \"name\": \"id\",\n \"required\": true,\n \"schema\": {\n \"maxLength\": 1000,\n \"minLength\": 1,\n \"type\": \"string\"\n }\n }\n ],\n \"path\": \"/bulk/imports/{id}\",\n \"request_body\": null,\n \"security\": null,\n \"skill_name\": \"describe_bulk_import\",\n \"source_index\": 1,\n \"source_openapi_url\": \"https://raw.githubusercontent.com/pinecone-io/pinecone-api/main/2025-04/db_data_2025-04.oas.yaml\",\n \"source_title\": \"Pinecone Data Plane API\",\n \"summary\": \"Describe an import\",\n \"tags\": [\n \"Bulk Operations\"\n ]\n },\n \"describe_index_stats\": {\n \"base_url\": \"https://{index_host}\",\n \"base_url_field\": \"OPENAPI_BASE_URL\",\n \"description\": \"Return statistics about the contents of an index, including the vector count per namespace, the number of dimensions, and the index fullness.\\n\\nServerless indexes scale automatically as needed, so index fullness is relevant only for pod-based indexes.\",\n \"destructive\": true,\n \"method\": \"POST\",\n \"operation_id\": \"describe_index_stats\",\n \"parameters\": [],\n \"path\": \"/describe_index_stats\",\n \"request_body\": {\n \"$ref\": \"#/components/schemas/DescribeIndexStatsRequest\"\n },\n \"security\": null,\n \"skill_name\": \"describe_index_stats\",\n \"source_index\": 1,\n \"source_openapi_url\": \"https://raw.githubusercontent.com/pinecone-io/pinecone-api/main/2025-04/db_data_2025-04.oas.yaml\",\n \"source_title\": \"Pinecone Data Plane API\",\n \"summary\": \"Get index stats\",\n \"tags\": [\n \"Vector Operations\"\n ]\n },\n \"describe_namespace\": {\n \"base_url\": \"https://{index_host}\",\n \"base_url_field\": \"OPENAPI_BASE_URL\",\n \"description\": \"Describe a namespace in a serverless index, including the total number of vectors in the namespace.\\n\\nFor guidance and examples, see [Manage namespaces](https://docs.pinecone.io/guides/manage-data/manage-namespaces).\\n\\n**Note:** This operation is not supported for pod-based indexes.\",\n \"destructive\": false,\n \"method\": \"GET\",\n \"operation_id\": \"describe_namespace\",\n \"parameters\": [\n {\n \"description\": \"The namespace to describe\",\n \"in\": \"path\",\n \"name\": \"namespace\",\n \"required\": true,\n \"schema\": {\n \"type\": \"string\"\n }\n }\n ],\n \"path\": \"/namespaces/{namespace}\",\n \"request_body\": null,\n \"security\": null,\n \"skill_name\": \"describe_namespace\",\n \"source_index\": 1,\n \"source_openapi_url\": \"https://raw.githubusercontent.com/pinecone-io/pinecone-api/main/2025-04/db_data_2025-04.oas.yaml\",\n \"source_title\": \"Pinecone Data Plane API\",\n \"summary\": \"Describe a namespace\",\n \"tags\": [\n \"Namespace Operations\"\n ]\n },\n \"fetch_vectors\": {\n \"base_url\": \"https://{index_host}\",\n \"base_url_field\": \"OPENAPI_BASE_URL\",\n \"description\": \"Look up and return vectors by ID from a single namespace. The returned vectors include the vector data and/or metadata.\\n\\nFor on-demand indexes, since vector values are retrieved from object storage, fetch operations may have increased latency. If you only need metadata or IDs, consider using the query operation with `includeValues` set to `false` instead.\\n\\nFor guidance and examples, see [Fetch data](https://docs.pinecone.io/guides/manage-data/fetch-data).\",\n \"destructive\": false,\n \"method\": \"GET\",\n \"operation_id\": \"fetch_vectors\",\n \"parameters\": [\n {\n \"description\": \"The vector IDs to fetch. Does not accept values containing spaces.\",\n \"in\": \"query\",\n \"name\": \"ids\",\n \"required\": true,\n \"schema\": {\n \"items\": {\n \"type\": \"string\"\n },\n \"type\": \"array\"\n }\n },\n {\n \"description\": \"\",\n \"in\": \"query\",\n \"name\": \"namespace\",\n \"required\": false,\n \"schema\": {\n \"type\": \"string\"\n }\n }\n ],\n \"path\": \"/vectors/fetch\",\n \"request_body\": null,\n \"security\": null,\n \"skill_name\": \"fetch_vectors\",\n \"source_index\": 1,\n \"source_openapi_url\": \"https://raw.githubusercontent.com/pinecone-io/pinecone-api/main/2025-04/db_data_2025-04.oas.yaml\",\n \"source_title\": \"Pinecone Data Plane API\",\n \"summary\": \"Fetch vectors\",\n \"tags\": [\n \"Vector Operations\"\n ]\n },\n \"list_bulk_imports\": {\n \"base_url\": \"https://{index_host}\",\n \"base_url_field\": \"OPENAPI_BASE_URL\",\n \"description\": \"List all recent and ongoing import operations.\\n\\nBy default, `list_imports` returns up to 100 imports per page. If the `limit` parameter is set, `list` returns up to that number of imports instead. Whenever there are additional IDs to return, the response also includes a `pagination_token` that you can use to get the next batch of imports. When the response does not include a `pagination_token`, there are no more imports to return.\\n\\nFor guidance and examples, see [Import data](https://docs.pinecone.io/guides/index-data/import-data).\",\n \"destructive\": false,\n \"method\": \"GET\",\n \"operation_id\": \"list_bulk_imports\",\n \"parameters\": [\n {\n \"description\": \"Max number of operations to return per page.\",\n \"in\": \"query\",\n \"name\": \"limit\",\n \"required\": false,\n \"schema\": {\n \"default\": \"100\",\n \"format\": \"int32\",\n \"maximum\": 100,\n \"minimum\": 1,\n \"type\": \"integer\"\n }\n },\n {\n \"description\": \"Pagination token to continue a previous listing operation.\",\n \"in\": \"query\",\n \"name\": \"paginationToken\",\n \"required\": false,\n \"schema\": {\n \"type\": \"string\"\n }\n }\n ],\n \"path\": \"/bulk/imports\",\n \"request_body\": null,\n \"security\": null,\n \"skill_name\": \"list_bulk_imports\",\n \"source_index\": 1,\n \"source_openapi_url\": \"https://raw.githubusercontent.com/pinecone-io/pinecone-api/main/2025-04/db_data_2025-04.oas.yaml\",\n \"source_title\": \"Pinecone Data Plane API\",\n \"summary\": \"List imports\",\n \"tags\": [\n \"Bulk Operations\"\n ]\n },\n \"list_namespaces_operation\": {\n \"base_url\": \"https://{index_host}\",\n \"base_url_field\": \"OPENAPI_BASE_URL\",\n \"description\": \"List all namespaces in a serverless index.\\n\\nUp to 100 namespaces are returned at a time by default, in sorted order (bitwise \\u201cC\\u201d collation). If the `limit` parameter is set, up to that number of namespaces are returned instead. Whenever there are additional namespaces to return, the response also includes a `pagination_token` that you can use to get the next batch of namespaces. When the response does not include a `pagination_token`, there are no more namespaces to return.\\n\\nFor guidance and examples, see [Manage namespaces](https://docs.pinecone.io/guides/manage-data/manage-namespaces).\\n\\n**Note:** This operation is not supported for pod-based indexes.\",\n \"destructive\": false,\n \"method\": \"GET\",\n \"operation_id\": \"list_namespaces_operation\",\n \"parameters\": [\n {\n \"description\": \"Max number namespaces to return per page.\",\n \"in\": \"query\",\n \"name\": \"limit\",\n \"required\": false,\n \"schema\": {\n \"format\": \"int32\",\n \"type\": \"integer\"\n }\n },\n {\n \"description\": \"Pagination token to continue a previous listing operation.\",\n \"in\": \"query\",\n \"name\": \"paginationToken\",\n \"required\": false,\n \"schema\": {\n \"type\": \"string\"\n }\n }\n ],\n \"path\": \"/namespaces\",\n \"request_body\": null,\n \"security\": null,\n \"skill_name\": \"list_namespaces_operation\",\n \"source_index\": 1,\n \"source_openapi_url\": \"https://raw.githubusercontent.com/pinecone-io/pinecone-api/main/2025-04/db_data_2025-04.oas.yaml\",\n \"source_title\": \"Pinecone Data Plane API\",\n \"summary\": \"List namespaces\",\n \"tags\": [\n \"Namespace Operations\"\n ]\n },\n \"list_vectors\": {\n \"base_url\": \"https://{index_host}\",\n \"base_url_field\": \"OPENAPI_BASE_URL\",\n \"description\": \"List the IDs of vectors in a single namespace of a serverless index. An optional prefix can be passed to limit the results to IDs with a common prefix.\\n\\nReturns up to 100 IDs at a time by default in sorted order (bitwise \\\"C\\\" collation). If the `limit` parameter is set, `list` returns up to that number of IDs instead. Whenever there are additional IDs to return, the response also includes a `pagination_token` that you can use to get the next batch of IDs. When the response does not include a `pagination_token`, there are no more IDs to return.\\n\\nFor guidance and examples, see [List record IDs](https://docs.pinecone.io/guides/manage-data/list-record-ids).\\n\\n**Note:** `list` is supported only for serverless indexes.\",\n \"destructive\": false,\n \"method\": \"GET\",\n \"operation_id\": \"list_vectors\",\n \"parameters\": [\n {\n \"description\": \"The vector IDs to fetch. Does not accept values containing spaces.\",\n \"in\": \"query\",\n \"name\": \"prefix\",\n \"required\": false,\n \"schema\": {\n \"type\": \"string\"\n }\n },\n {\n \"description\": \"Max number of IDs to return per page.\",\n \"in\": \"query\",\n \"name\": \"limit\",\n \"required\": false,\n \"schema\": {\n \"default\": \"100\",\n \"format\": \"int64\",\n \"type\": \"integer\"\n }\n },\n {\n \"description\": \"Pagination token to continue a previous listing operation.\",\n \"in\": \"query\",\n \"name\": \"paginationToken\",\n \"required\": false,\n \"schema\": {\n \"type\": \"string\"\n }\n },\n {\n \"description\": \"\",\n \"in\": \"query\",\n \"name\": \"namespace\",\n \"required\": false,\n \"schema\": {\n \"type\": \"string\"\n }\n }\n ],\n \"path\": \"/vectors/list\",\n \"request_body\": null,\n \"security\": null,\n \"skill_name\": \"list_vectors\",\n \"source_index\": 1,\n \"source_openapi_url\": \"https://raw.githubusercontent.com/pinecone-io/pinecone-api/main/2025-04/db_data_2025-04.oas.yaml\",\n \"source_title\": \"Pinecone Data Plane API\",\n \"summary\": \"List vector IDs\",\n \"tags\": [\n \"Vector Operations\"\n ]\n },\n \"query_vectors\": {\n \"base_url\": \"https://{index_host}\",\n \"base_url_field\": \"OPENAPI_BASE_URL\",\n \"description\": \"Search a namespace using a query vector. It retrieves the ids of the most similar items in a namespace, along with their similarity scores.\\n\\nFor guidance, examples, and limits, see [Search](https://docs.pinecone.io/guides/search/search-overview).\",\n \"destructive\": true,\n \"method\": \"POST\",\n \"operation_id\": \"query_vectors\",\n \"parameters\": [],\n \"path\": \"/query\",\n \"request_body\": {\n \"$ref\": \"#/components/schemas/QueryRequest\"\n },\n \"security\": null,\n \"skill_name\": \"query_vectors\",\n \"source_index\": 1,\n \"source_openapi_url\": \"https://raw.githubusercontent.com/pinecone-io/pinecone-api/main/2025-04/db_data_2025-04.oas.yaml\",\n \"source_title\": \"Pinecone Data Plane API\",\n \"summary\": \"Search with a vector\",\n \"tags\": [\n \"Vector Operations\"\n ]\n },\n \"search_records_namespace\": {\n \"base_url\": \"https://{index_host}\",\n \"base_url_field\": \"OPENAPI_BASE_URL\",\n \"description\": \"Search a namespace with a query text, query vector, or record ID and return the most similar records, along with their similarity scores. Optionally, rerank the initial results based on their relevance to the query. \\n\\nSearching with text is supported only for [indexes with integrated embedding](https://docs.pinecone.io/guides/indexes/create-an-index#integrated-embedding). Searching with a query vector or record ID is supported for all indexes. \\n\\nFor guidance, examples, and limits, see [Search](https://docs.pinecone.io/guides/search/search-overview).\",\n \"destructive\": true,\n \"method\": \"POST\",\n \"operation_id\": \"search_records_namespace\",\n \"parameters\": [\n {\n \"description\": \"The namespace to search.\",\n \"in\": \"path\",\n \"name\": \"namespace\",\n \"required\": true,\n \"schema\": {\n \"type\": \"string\"\n }\n }\n ],\n \"path\": \"/records/namespaces/{namespace}/search\",\n \"request_body\": {\n \"$ref\": \"#/components/schemas/SearchRecordsRequest\"\n },\n \"security\": null,\n \"skill_name\": \"search_records_namespace\",\n \"source_index\": 1,\n \"source_openapi_url\": \"https://raw.githubusercontent.com/pinecone-io/pinecone-api/main/2025-04/db_data_2025-04.oas.yaml\",\n \"source_title\": \"Pinecone Data Plane API\",\n \"summary\": \"Search with text\",\n \"tags\": [\n \"Vector Operations\"\n ]\n },\n \"start_bulk_import\": {\n \"base_url\": \"https://{index_host}\",\n \"base_url_field\": \"OPENAPI_BASE_URL\",\n \"description\": \"Start an asynchronous import of vectors from object storage into an index.\\n\\nFor guidance and examples, see [Import data](https://docs.pinecone.io/guides/index-data/import-data).\",\n \"destructive\": true,\n \"method\": \"POST\",\n \"operation_id\": \"start_bulk_import\",\n \"parameters\": [],\n \"path\": \"/bulk/imports\",\n \"request_body\": {\n \"$ref\": \"#/components/schemas/StartImportRequest\"\n },\n \"security\": null,\n \"skill_name\": \"start_bulk_import\",\n \"source_index\": 1,\n \"source_openapi_url\": \"https://raw.githubusercontent.com/pinecone-io/pinecone-api/main/2025-04/db_data_2025-04.oas.yaml\",\n \"source_title\": \"Pinecone Data Plane API\",\n \"summary\": \"Start import\",\n \"tags\": [\n \"Bulk Operations\"\n ]\n },\n \"update_vector\": {\n \"base_url\": \"https://{index_host}\",\n \"base_url_field\": \"OPENAPI_BASE_URL\",\n \"description\": \"Update a vector in a namespace. If a value is included, it will overwrite the previous value. If a `set_metadata` is included, the values of the fields specified in it will be added or overwrite the previous value.\\n\\nFor guidance and examples, see [Update data](https://docs.pinecone.io/guides/manage-data/update-data).\",\n \"destructive\": true,\n \"method\": \"POST\",\n \"operation_id\": \"update_vector\",\n \"parameters\": [],\n \"path\": \"/vectors/update\",\n \"request_body\": {\n \"$ref\": \"#/components/schemas/UpdateRequest\"\n },\n \"security\": null,\n \"skill_name\": \"update_vector\",\n \"source_index\": 1,\n \"source_openapi_url\": \"https://raw.githubusercontent.com/pinecone-io/pinecone-api/main/2025-04/db_data_2025-04.oas.yaml\",\n \"source_title\": \"Pinecone Data Plane API\",\n \"summary\": \"Update a vector\",\n \"tags\": [\n \"Vector Operations\"\n ]\n },\n \"upsert_records_namespace\": {\n \"base_url\": \"https://{index_host}\",\n \"base_url_field\": \"OPENAPI_BASE_URL\",\n \"description\": \"Upsert text into a namespace. Pinecone converts the text to vectors automatically using the hosted embedding model associated with the index.\\n\\nUpserting text is supported only for [indexes with integrated embedding](https://docs.pinecone.io/guides/index-data/create-an-index#embedding-models).\\n\\nFor guidance, examples, and limits, see [Upsert data](https://docs.pinecone.io/guides/index-data/upsert-data).\",\n \"destructive\": true,\n \"method\": \"POST\",\n \"operation_id\": \"upsert_records_namespace\",\n \"parameters\": [\n {\n \"description\": \"The namespace to upsert records into.\",\n \"in\": \"path\",\n \"name\": \"namespace\",\n \"required\": true,\n \"schema\": {\n \"type\": \"string\"\n }\n }\n ],\n \"path\": \"/records/namespaces/{namespace}/upsert\",\n \"request_body\": {\n \"items\": {\n \"$ref\": \"#/components/schemas/UpsertRecord\"\n },\n \"type\": \"array\"\n },\n \"security\": null,\n \"skill_name\": \"upsert_records_namespace\",\n \"source_index\": 1,\n \"source_openapi_url\": \"https://raw.githubusercontent.com/pinecone-io/pinecone-api/main/2025-04/db_data_2025-04.oas.yaml\",\n \"source_title\": \"Pinecone Data Plane API\",\n \"summary\": \"Upsert text\",\n \"tags\": [\n \"Vector Operations\"\n ]\n },\n \"upsert_vectors\": {\n \"base_url\": \"https://{index_host}\",\n \"base_url_field\": \"OPENAPI_BASE_URL\",\n \"description\": \"Upsert vectors into a namespace. If a new value is upserted for an existing vector ID, it will overwrite the previous value.\\n\\nFor guidance, examples, and limits, see [Upsert data](https://docs.pinecone.io/guides/index-data/upsert-data).\",\n \"destructive\": true,\n \"method\": \"POST\",\n \"operation_id\": \"upsert_vectors\",\n \"parameters\": [],\n \"path\": \"/vectors/upsert\",\n \"request_body\": {\n \"$ref\": \"#/components/schemas/UpsertRequest\"\n },\n \"security\": null,\n \"skill_name\": \"upsert_vectors\",\n \"source_index\": 1,\n \"source_openapi_url\": \"https://raw.githubusercontent.com/pinecone-io/pinecone-api/main/2025-04/db_data_2025-04.oas.yaml\",\n \"source_title\": \"Pinecone Data Plane API\",\n \"summary\": \"Upsert vectors\",\n \"tags\": [\n \"Vector Operations\"\n ]\n }\n}")
|
|
OPERATION_GROUPS = json.loads("[]")
|
|
ROOT_SECURITY = json.loads("[\n {\n \"ApiKeyAuth\": []\n }\n]")
|
|
SECURITY_SCHEMES = json.loads("{\n \"ApiKeyAuth\": {\n \"description\": \"An API Key is required to call Pinecone APIs. Get yours from the [console](https://app.pinecone.io/).\",\n \"in\": \"header\",\n \"name\": \"Api-Key\",\n \"type\": \"apiKey\"\n }\n}")
|
|
SECURITY_FIELDS = json.loads("{\n \"ApiKeyAuth\": {\n \"field\": \"API_KEY\",\n \"kind\": \"apiKey\",\n \"location\": \"header\",\n \"name\": \"Api-Key\"\n }\n}")
|
|
PATH_PARAMETER_RE = re.compile(r"{([^}/]+)}")
|
|
SOURCE_ROOT = Path(globals().get("__file__", "agent.py")).resolve().parent
|
|
SOURCE_SKILLS_DIR = SOURCE_ROOT / "skills"
|
|
RUNTIME_SKILLS_DIR = ".deepagents/openapi-skills/"
|
|
|
|
|
|
class OperationInput(BaseModel):
|
|
parameters: dict[str, Any] = Field(
|
|
default_factory=dict,
|
|
description="Path, query, header, and cookie parameters keyed by OpenAPI parameter name.",
|
|
)
|
|
body: Any | None = Field(default=None, description="JSON request body, when the operation accepts one.")
|
|
|
|
|
|
class PineconeOpenapiAgent(A2AAgent):
|
|
name = "pinecone-openapi-agent"
|
|
description = "Vector database data-plane API for records, vectors, namespaces, search, and fetch operations."
|
|
version = "2025-04"
|
|
consumer_setup = ConsumerSetup.from_fields(
|
|
ConsumerSetupField.config("OPENAPI_BASE_URL", label="API base URL", description="Override the default API server (https://{index_host}).", required=False, input_type="url"),
|
|
ConsumerSetupField.secret("API_KEY", label="ApiKeyAuth API key", description="An API Key is required to call Pinecone APIs. Get yours from the [console](https://app.pinecone.io/).", required=True),
|
|
)
|
|
llm_provisioning = LLMProvisioning.PLATFORM
|
|
pricing = Pricing(
|
|
price_per_call_usd=0.0,
|
|
caller_pays_llm=True,
|
|
notes="Uses the caller's saved LLM credential through ctx.llm.",
|
|
)
|
|
resources = Resources(cpu="200m", memory="512Mi")
|
|
egress = EgressPolicy(
|
|
allow_hosts=('{index_host}',),
|
|
deny_internet_by_default=True,
|
|
)
|
|
tools_used = ("openapi", "deepagents")
|
|
capabilities = {
|
|
"openapi_auto_agent": {
|
|
"operation_count": len(OPERATIONS),
|
|
"default_base_url": DEFAULT_BASE_URL,
|
|
"source_openapi_url": 'https://raw.githubusercontent.com/pinecone-io/pinecone-api/main/2025-04/db_data_2025-04.oas.yaml',
|
|
"source_openapi_urls": ['https://raw.githubusercontent.com/pinecone-io/pinecone-api/main/2025-04/db_data_2025-04.oas.yaml'],
|
|
"server_urls": ['https://{index_host}'],
|
|
"regenerable": True,
|
|
"security_schemes": list(SECURITY_SCHEMES),
|
|
}
|
|
}
|
|
|
|
@skill(
|
|
name="auto",
|
|
description="Use the OpenAPI service to complete a natural-language goal.",
|
|
tags=("openapi", "auto"),
|
|
timeout_seconds=900,
|
|
)
|
|
async def auto(self, ctx: RunContext, goal: str) -> dict[str, Any]:
|
|
creds = ctx.llm
|
|
if not creds.api_key:
|
|
return {
|
|
"error": "llm_credentials_missing",
|
|
"final": (
|
|
"LLM key required. Add an LLM credential in Settings > "
|
|
"LLM credentials before running this agent."
|
|
),
|
|
"messages": [],
|
|
}
|
|
graph = create_a2a_deep_agent(
|
|
ctx,
|
|
creds=creds,
|
|
tools=self._operation_tools(ctx),
|
|
system_prompt=self._system_prompt(),
|
|
)
|
|
result = await graph.ainvoke({"messages": [{"role": "user", "content": goal}]})
|
|
messages = result.get("messages", []) if isinstance(result, dict) else []
|
|
final = _message_text(messages[-1]) if messages else result
|
|
return {
|
|
"final": final,
|
|
"messages": [_message_to_dict(message) for message in messages[-8:]],
|
|
}
|
|
|
|
@skill(
|
|
name="list_bulk_imports",
|
|
description="GET /bulk/imports - List imports",
|
|
tags=('Bulk Operations',),
|
|
timeout_seconds=60,
|
|
)
|
|
async def list_bulk_imports(
|
|
self,
|
|
ctx: RunContext,
|
|
parameters: dict[str, Any] | None = None,
|
|
body: Any | None = None,
|
|
) -> dict[str, Any]:
|
|
return await self._request(
|
|
ctx,
|
|
"list_bulk_imports",
|
|
parameters=parameters or {},
|
|
body=body,
|
|
)
|
|
|
|
@skill(
|
|
name="start_bulk_import",
|
|
description="POST /bulk/imports - Start import",
|
|
tags=('Bulk Operations',),
|
|
timeout_seconds=120,
|
|
)
|
|
async def start_bulk_import(
|
|
self,
|
|
ctx: RunContext,
|
|
parameters: dict[str, Any] | None = None,
|
|
body: Any | None = None,
|
|
) -> dict[str, Any]:
|
|
return await self._request(
|
|
ctx,
|
|
"start_bulk_import",
|
|
parameters=parameters or {},
|
|
body=body,
|
|
)
|
|
|
|
@skill(
|
|
name="describe_bulk_import",
|
|
description="GET /bulk/imports/{id} - Describe an import",
|
|
tags=('Bulk Operations',),
|
|
timeout_seconds=60,
|
|
)
|
|
async def describe_bulk_import(
|
|
self,
|
|
ctx: RunContext,
|
|
parameters: dict[str, Any] | None = None,
|
|
body: Any | None = None,
|
|
) -> dict[str, Any]:
|
|
return await self._request(
|
|
ctx,
|
|
"describe_bulk_import",
|
|
parameters=parameters or {},
|
|
body=body,
|
|
)
|
|
|
|
@skill(
|
|
name="cancel_bulk_import",
|
|
description="DELETE /bulk/imports/{id} - Cancel an import",
|
|
tags=('Bulk Operations',),
|
|
timeout_seconds=120,
|
|
)
|
|
async def cancel_bulk_import(
|
|
self,
|
|
ctx: RunContext,
|
|
parameters: dict[str, Any] | None = None,
|
|
body: Any | None = None,
|
|
) -> dict[str, Any]:
|
|
return await self._request(
|
|
ctx,
|
|
"cancel_bulk_import",
|
|
parameters=parameters or {},
|
|
body=body,
|
|
)
|
|
|
|
@skill(
|
|
name="describe_index_stats",
|
|
description="POST /describe_index_stats - Get index stats",
|
|
tags=('Vector Operations',),
|
|
timeout_seconds=120,
|
|
)
|
|
async def describe_index_stats(
|
|
self,
|
|
ctx: RunContext,
|
|
parameters: dict[str, Any] | None = None,
|
|
body: Any | None = None,
|
|
) -> dict[str, Any]:
|
|
return await self._request(
|
|
ctx,
|
|
"describe_index_stats",
|
|
parameters=parameters or {},
|
|
body=body,
|
|
)
|
|
|
|
@skill(
|
|
name="query_vectors",
|
|
description="POST /query - Search with a vector",
|
|
tags=('Vector Operations',),
|
|
timeout_seconds=120,
|
|
)
|
|
async def query_vectors(
|
|
self,
|
|
ctx: RunContext,
|
|
parameters: dict[str, Any] | None = None,
|
|
body: Any | None = None,
|
|
) -> dict[str, Any]:
|
|
return await self._request(
|
|
ctx,
|
|
"query_vectors",
|
|
parameters=parameters or {},
|
|
body=body,
|
|
)
|
|
|
|
@skill(
|
|
name="delete_vectors",
|
|
description="POST /vectors/delete - Delete vectors",
|
|
tags=('Vector Operations',),
|
|
timeout_seconds=120,
|
|
)
|
|
async def delete_vectors(
|
|
self,
|
|
ctx: RunContext,
|
|
parameters: dict[str, Any] | None = None,
|
|
body: Any | None = None,
|
|
) -> dict[str, Any]:
|
|
return await self._request(
|
|
ctx,
|
|
"delete_vectors",
|
|
parameters=parameters or {},
|
|
body=body,
|
|
)
|
|
|
|
@skill(
|
|
name="fetch_vectors",
|
|
description="GET /vectors/fetch - Fetch vectors",
|
|
tags=('Vector Operations',),
|
|
timeout_seconds=60,
|
|
)
|
|
async def fetch_vectors(
|
|
self,
|
|
ctx: RunContext,
|
|
parameters: dict[str, Any] | None = None,
|
|
body: Any | None = None,
|
|
) -> dict[str, Any]:
|
|
return await self._request(
|
|
ctx,
|
|
"fetch_vectors",
|
|
parameters=parameters or {},
|
|
body=body,
|
|
)
|
|
|
|
@skill(
|
|
name="list_vectors",
|
|
description="GET /vectors/list - List vector IDs",
|
|
tags=('Vector Operations',),
|
|
timeout_seconds=60,
|
|
)
|
|
async def list_vectors(
|
|
self,
|
|
ctx: RunContext,
|
|
parameters: dict[str, Any] | None = None,
|
|
body: Any | None = None,
|
|
) -> dict[str, Any]:
|
|
return await self._request(
|
|
ctx,
|
|
"list_vectors",
|
|
parameters=parameters or {},
|
|
body=body,
|
|
)
|
|
|
|
@skill(
|
|
name="update_vector",
|
|
description="POST /vectors/update - Update a vector",
|
|
tags=('Vector Operations',),
|
|
timeout_seconds=120,
|
|
)
|
|
async def update_vector(
|
|
self,
|
|
ctx: RunContext,
|
|
parameters: dict[str, Any] | None = None,
|
|
body: Any | None = None,
|
|
) -> dict[str, Any]:
|
|
return await self._request(
|
|
ctx,
|
|
"update_vector",
|
|
parameters=parameters or {},
|
|
body=body,
|
|
)
|
|
|
|
@skill(
|
|
name="upsert_vectors",
|
|
description="POST /vectors/upsert - Upsert vectors",
|
|
tags=('Vector Operations',),
|
|
timeout_seconds=120,
|
|
)
|
|
async def upsert_vectors(
|
|
self,
|
|
ctx: RunContext,
|
|
parameters: dict[str, Any] | None = None,
|
|
body: Any | None = None,
|
|
) -> dict[str, Any]:
|
|
return await self._request(
|
|
ctx,
|
|
"upsert_vectors",
|
|
parameters=parameters or {},
|
|
body=body,
|
|
)
|
|
|
|
@skill(
|
|
name="list_namespaces_operation",
|
|
description="GET /namespaces - List namespaces",
|
|
tags=('Namespace Operations',),
|
|
timeout_seconds=60,
|
|
)
|
|
async def list_namespaces_operation(
|
|
self,
|
|
ctx: RunContext,
|
|
parameters: dict[str, Any] | None = None,
|
|
body: Any | None = None,
|
|
) -> dict[str, Any]:
|
|
return await self._request(
|
|
ctx,
|
|
"list_namespaces_operation",
|
|
parameters=parameters or {},
|
|
body=body,
|
|
)
|
|
|
|
@skill(
|
|
name="describe_namespace",
|
|
description="GET /namespaces/{namespace} - Describe a namespace",
|
|
tags=('Namespace Operations',),
|
|
timeout_seconds=60,
|
|
)
|
|
async def describe_namespace(
|
|
self,
|
|
ctx: RunContext,
|
|
parameters: dict[str, Any] | None = None,
|
|
body: Any | None = None,
|
|
) -> dict[str, Any]:
|
|
return await self._request(
|
|
ctx,
|
|
"describe_namespace",
|
|
parameters=parameters or {},
|
|
body=body,
|
|
)
|
|
|
|
@skill(
|
|
name="delete_namespace",
|
|
description="DELETE /namespaces/{namespace} - Delete a namespace",
|
|
tags=('Namespace Operations',),
|
|
timeout_seconds=120,
|
|
)
|
|
async def delete_namespace(
|
|
self,
|
|
ctx: RunContext,
|
|
parameters: dict[str, Any] | None = None,
|
|
body: Any | None = None,
|
|
) -> dict[str, Any]:
|
|
return await self._request(
|
|
ctx,
|
|
"delete_namespace",
|
|
parameters=parameters or {},
|
|
body=body,
|
|
)
|
|
|
|
@skill(
|
|
name="upsert_records_namespace",
|
|
description="POST /records/namespaces/{namespace}/upsert - Upsert text",
|
|
tags=('Vector Operations',),
|
|
timeout_seconds=120,
|
|
)
|
|
async def upsert_records_namespace(
|
|
self,
|
|
ctx: RunContext,
|
|
parameters: dict[str, Any] | None = None,
|
|
body: Any | None = None,
|
|
) -> dict[str, Any]:
|
|
return await self._request(
|
|
ctx,
|
|
"upsert_records_namespace",
|
|
parameters=parameters or {},
|
|
body=body,
|
|
)
|
|
|
|
@skill(
|
|
name="search_records_namespace",
|
|
description="POST /records/namespaces/{namespace}/search - Search with text",
|
|
tags=('Vector Operations',),
|
|
timeout_seconds=120,
|
|
)
|
|
async def search_records_namespace(
|
|
self,
|
|
ctx: RunContext,
|
|
parameters: dict[str, Any] | None = None,
|
|
body: Any | None = None,
|
|
) -> dict[str, Any]:
|
|
return await self._request(
|
|
ctx,
|
|
"search_records_namespace",
|
|
parameters=parameters or {},
|
|
body=body,
|
|
)
|
|
|
|
def _operation_subagents(self, ctx: RunContext, skills_root: str) -> list[dict[str, Any]]:
|
|
subagents: list[dict[str, Any]] = []
|
|
for group in OPERATION_GROUPS:
|
|
skill_path = (
|
|
f"{skills_root}{group['skill_dir']}/"
|
|
if skills_root
|
|
else ""
|
|
)
|
|
subagent = {
|
|
"name": group["subagent_name"],
|
|
"description": group["description"],
|
|
"system_prompt": self._subagent_prompt(group),
|
|
"tools": self._operation_tools(ctx, set(group["operation_ids"])),
|
|
}
|
|
if skill_path:
|
|
subagent["skills"] = [skill_path]
|
|
subagents.append(subagent)
|
|
return subagents
|
|
|
|
def _operation_tools(
|
|
self,
|
|
ctx: RunContext,
|
|
operation_ids: set[str] | None = None,
|
|
) -> list[StructuredTool]:
|
|
tools: list[StructuredTool] = []
|
|
for operation_id, operation in OPERATIONS.items():
|
|
if operation_ids is not None and operation_id not in operation_ids:
|
|
continue
|
|
async def call(
|
|
parameters: dict[str, Any] | None = None,
|
|
body: Any | None = None,
|
|
*,
|
|
_operation_id: str = operation_id,
|
|
) -> dict[str, Any]:
|
|
return await self._request(
|
|
ctx,
|
|
_operation_id,
|
|
parameters=parameters or {},
|
|
body=body,
|
|
)
|
|
|
|
tools.append(
|
|
StructuredTool.from_function(
|
|
coroutine=call,
|
|
name=operation["skill_name"],
|
|
description=self._tool_description(operation),
|
|
args_schema=OperationInput,
|
|
)
|
|
)
|
|
return tools
|
|
|
|
def _system_prompt(self) -> str:
|
|
if OPERATION_GROUPS:
|
|
lines = [
|
|
"You coordinate route-specific OpenAPI subagents.",
|
|
"Delegate API work to the matching subagent with the task tool.",
|
|
"Do not invent API responses; ask subagents to call their tools for real results.",
|
|
"If a subagent reports missing consumer setup, tell the user which setup field is required.",
|
|
"If a subagent reports that the generated OpenAPI agent may be stale, ask whether the user wants to refresh it from the latest OpenAPI spec.",
|
|
"",
|
|
"Available route groups:",
|
|
]
|
|
for group in OPERATION_GROUPS:
|
|
lines.append(
|
|
f"- {group['subagent_name']}: {group['description']}"
|
|
)
|
|
return "\n".join(lines)
|
|
lines = [
|
|
"You operate an API through generated OpenAPI tools.",
|
|
"Call tools to get real results. Do not invent API responses.",
|
|
"For write, update, or delete operations, explain the intended action before calling the tool.",
|
|
"If an operation reports missing consumer setup, tell the user which setup field is required.",
|
|
"If an operation returns 404, 405, 410, or a schema/validation error that suggests the live API no longer matches these tools, tell the user this generated agent may need to be refreshed from the latest OpenAPI spec and ask whether they want to refresh it.",
|
|
"",
|
|
"Available operations:",
|
|
]
|
|
for operation in OPERATIONS.values():
|
|
marker = "WRITE" if operation.get("destructive") else "READ"
|
|
lines.append(
|
|
f"- {operation['skill_name']}: {marker} {operation['method']} {operation['path']} — {operation['summary']}"
|
|
)
|
|
return "\n".join(lines)
|
|
|
|
def _subagent_prompt(self, group: dict[str, Any]) -> str:
|
|
lines = [
|
|
"You operate one route group from a generated OpenAPI API.",
|
|
"Use the available operation tools to make real API calls. Do not invent API responses.",
|
|
"Read the route group's SKILL.md when it applies; it lists every route you cover.",
|
|
"For write, update, or delete operations, explain the intended action before calling the tool.",
|
|
"If an operation reports missing consumer setup, return the exact setup field name.",
|
|
"If an operation returns 404, 405, 410, or a schema/validation error that suggests the live API no longer matches these tools, say the generated agent may need to be refreshed from the latest OpenAPI spec.",
|
|
"",
|
|
f"Route group: {group['label']}",
|
|
f"Common prefix: {group.get('common_prefix') or '/'}",
|
|
"Available operation tools:",
|
|
]
|
|
for operation_id in group["operation_ids"]:
|
|
operation = OPERATIONS[operation_id]
|
|
marker = "WRITE" if operation.get("destructive") else "READ"
|
|
lines.append(
|
|
f"- {operation['skill_name']}: {marker} {operation['method']} {operation['path']} - {operation['summary']}"
|
|
)
|
|
return "\n".join(lines)
|
|
|
|
def _tool_description(self, operation: dict[str, Any]) -> str:
|
|
parts = [
|
|
f"{operation['method']} {operation['path']}",
|
|
str(operation.get("description") or operation.get("summary") or ""),
|
|
]
|
|
if operation.get("parameters"):
|
|
parts.append(
|
|
"Parameters: "
|
|
+ ", ".join(
|
|
f"{p['name']} in {p['in']}{' required' if p.get('required') else ''}"
|
|
for p in operation["parameters"]
|
|
)
|
|
)
|
|
if operation.get("request_body") is not None:
|
|
parts.append("Accepts a JSON request body.")
|
|
return "\n".join(part for part in parts if part)
|
|
|
|
async def _request(
|
|
self,
|
|
ctx: RunContext,
|
|
operation_id: str,
|
|
*,
|
|
parameters: dict[str, Any],
|
|
body: Any | None,
|
|
) -> dict[str, Any]:
|
|
operation = OPERATIONS[operation_id]
|
|
default_base_url = str(operation.get("base_url") or DEFAULT_BASE_URL).rstrip("/")
|
|
base_url_field = str(operation.get("base_url_field") or "OPENAPI_BASE_URL")
|
|
base_url = str(ctx.consumer_config(base_url_field, default_base_url) or default_base_url).rstrip("/")
|
|
url, query, headers = self._request_parts(ctx, operation, parameters)
|
|
request_kwargs: dict[str, Any] = {
|
|
"params": query,
|
|
"headers": headers,
|
|
}
|
|
if body is not None:
|
|
if isinstance(body, (bytes, bytearray)):
|
|
body = body.decode("utf-8", errors="replace")
|
|
if isinstance(body, str):
|
|
stripped = body.strip()
|
|
if stripped and stripped[0] in "{[":
|
|
try:
|
|
body = json.loads(stripped)
|
|
except ValueError:
|
|
pass
|
|
request_kwargs["json"] = body
|
|
async with httpx.AsyncClient(timeout=60.0, follow_redirects=True) as client:
|
|
response = await client.request(
|
|
operation["method"],
|
|
f"{base_url}{url}",
|
|
**request_kwargs,
|
|
)
|
|
content_type = response.headers.get("content-type", "")
|
|
try:
|
|
payload: Any = response.json() if "json" in content_type else response.text
|
|
except ValueError:
|
|
payload = response.text
|
|
if response.status_code >= 400:
|
|
out = {
|
|
"ok": False,
|
|
"status_code": response.status_code,
|
|
"operation_id": operation_id,
|
|
"error": payload,
|
|
}
|
|
if response.status_code in {404, 405, 410, 422}:
|
|
out["stale_openapi_hint"] = (
|
|
"This generated OpenAPI agent may be stale. Ask the user "
|
|
"whether they want to refresh it from the latest OpenAPI spec."
|
|
)
|
|
return out
|
|
return {
|
|
"ok": True,
|
|
"status_code": response.status_code,
|
|
"operation_id": operation_id,
|
|
"result": payload,
|
|
}
|
|
|
|
def _request_parts(
|
|
self,
|
|
ctx: RunContext,
|
|
operation: dict[str, Any],
|
|
parameters: dict[str, Any],
|
|
) -> tuple[str, dict[str, Any], dict[str, str]]:
|
|
path = operation["path"]
|
|
query: dict[str, Any] = {}
|
|
headers: dict[str, str] = {}
|
|
cookies: dict[str, Any] = {}
|
|
for param in operation.get("parameters") or []:
|
|
name = param["name"]
|
|
if name not in parameters:
|
|
if param.get("required"):
|
|
raise ValueError(f"missing required parameter {name!r}")
|
|
continue
|
|
value = parameters[name]
|
|
location = param["in"]
|
|
if location == "path":
|
|
path = path.replace("{" + name + "}", str(value))
|
|
elif location == "query":
|
|
query[name] = value
|
|
elif location == "header":
|
|
headers[name] = str(value)
|
|
elif location == "cookie":
|
|
cookies[name] = value
|
|
unresolved = PATH_PARAMETER_RE.findall(path)
|
|
if unresolved:
|
|
missing = ", ".join(sorted(set(unresolved)))
|
|
raise ValueError("missing required path parameter(s): " + missing)
|
|
if cookies:
|
|
headers["cookie"] = "; ".join(f"{key}={value}" for key, value in cookies.items())
|
|
auth_headers, auth_query = self._auth_for_operation(ctx, operation)
|
|
headers.update(auth_headers)
|
|
query.update(auth_query)
|
|
return path, query, headers
|
|
|
|
def _auth_for_operation(self, ctx: RunContext, operation: dict[str, Any]) -> tuple[dict[str, str], dict[str, Any]]:
|
|
requirements = operation.get("security")
|
|
if requirements is None:
|
|
requirements = ROOT_SECURITY
|
|
if requirements == []:
|
|
return {}, {}
|
|
missing: list[str] = []
|
|
for requirement in requirements or []:
|
|
if not isinstance(requirement, dict) or not requirement:
|
|
return {}, {}
|
|
headers: dict[str, str] = {}
|
|
query: dict[str, Any] = {}
|
|
ok = True
|
|
for scheme_name in requirement:
|
|
mapping = SECURITY_FIELDS.get(scheme_name) or {}
|
|
secret_name = mapping.get("field")
|
|
value = _consumer_secret_optional(ctx, secret_name) if secret_name else ""
|
|
if not value:
|
|
ok = False
|
|
if secret_name:
|
|
missing.append(secret_name)
|
|
continue
|
|
kind = mapping.get("kind")
|
|
if kind == "apiKey":
|
|
prefix = mapping.get("prefix") or ""
|
|
sent_value = f"{prefix}{value}"
|
|
if mapping.get("location") == "query":
|
|
query[mapping.get("name") or scheme_name] = sent_value
|
|
else:
|
|
headers[mapping.get("name") or scheme_name] = sent_value
|
|
elif kind in {"http", "oauth2"}:
|
|
scheme = mapping.get("scheme") or "Bearer"
|
|
if scheme.lower() == "basic":
|
|
token = base64.b64encode(value.encode("utf-8")).decode("ascii")
|
|
headers["authorization"] = f"Basic {token}"
|
|
else:
|
|
headers["authorization"] = f"{scheme} {value}"
|
|
else:
|
|
ok = False
|
|
if ok:
|
|
return headers, query
|
|
if missing:
|
|
raise ConsumerSetupMissing(
|
|
"operation requires consumer setup secret(s): "
|
|
+ ", ".join(sorted(set(missing)))
|
|
)
|
|
return {}, {}
|
|
|
|
|
|
def _consumer_secret_optional(ctx: RunContext, name: str | None) -> str:
|
|
if not name:
|
|
return ""
|
|
try:
|
|
return ctx.consumer_secret(name)
|
|
except ConsumerSetupMissing:
|
|
return ""
|
|
|
|
|
|
def _runtime_skills_root(ctx: RunContext) -> str:
|
|
workspace = getattr(ctx, "_workspace", None)
|
|
prefixes = tuple(getattr(workspace, "write_prefixes", ()) or ())
|
|
if not prefixes:
|
|
outputs_prefix = getattr(workspace, "outputs_prefix", None)
|
|
prefixes = (outputs_prefix or "outputs/",)
|
|
prefix = str(prefixes[0]).strip("/")
|
|
return f"/{prefix}/{RUNTIME_SKILLS_DIR}" if prefix else f"/{RUNTIME_SKILLS_DIR}"
|
|
|
|
|
|
def _seed_runtime_skills(backend: Any, ctx: RunContext) -> str:
|
|
if not SOURCE_SKILLS_DIR.exists():
|
|
return ""
|
|
runtime_root = _runtime_skills_root(ctx)
|
|
uploads: list[tuple[str, bytes]] = []
|
|
for path in SOURCE_SKILLS_DIR.rglob("*"):
|
|
if not path.is_file():
|
|
continue
|
|
rel = path.relative_to(SOURCE_SKILLS_DIR).as_posix()
|
|
uploads.append((runtime_root + rel, path.read_bytes()))
|
|
if not uploads:
|
|
return ""
|
|
backend.upload_files(uploads)
|
|
return runtime_root
|
|
|
|
|
|
def _message_text(message: Any) -> Any:
|
|
content = getattr(message, "content", message)
|
|
return content
|
|
|
|
|
|
def _message_to_dict(message: Any) -> dict[str, Any]:
|
|
if isinstance(message, BaseMessage):
|
|
return message.model_dump(mode="json")
|
|
if hasattr(message, "model_dump"):
|
|
return message.model_dump(mode="json")
|
|
if isinstance(message, dict):
|
|
return message
|
|
return {"content": str(message)}
|
|
|
|
|
|
agent = PineconeOpenapiAgent()
|