OKF v0.2 & Google Cloud Knowledge Catalog¶
vertebra.agent.okf parses Open Knowledge Format (OKF v0.2) bundles in Python with no PyYAML dependency. It validates truth blocks and footnotes, computes SHA-256 digests, and writes reproducible ZIP archives.
vertebra.agent.knowledge_catalog connects to Google Cloud Dataplex Universal Catalog (dataplex.googleapis.com/v1) over GcpTokenCache and HTTP/2. Sync and async clients resolve context-set entry groups, upload changed OkfBundle entries in batches of up to 250 by digest, and search entries via locations/global:searchEntries. See Agent Runtime for MCP, A2A, and workflow APIs.
Quick Example¶
from pathlib import Path
from vertebra.agent import (
AsyncKnowledgeCatalogClient,
KnowledgeCatalogConfig,
OkfBundle,
)
bundle = OkfBundle.from_directory(Path(".agents/bundles"))
archive_bytes = bundle.to_zip_bytes()
client = AsyncKnowledgeCatalogClient(
KnowledgeCatalogConfig(
project_id="my-gcp-project",
location="us-central1",
entry_group_id="okf-context",
)
)
await client.resolve_context_set(entry_group_id="okf-context")
summary = await client.sync_bundle(bundle, entry_group_id="okf-context")
matches = await client.search_entries(
"protocol harness",
entry_group_id="okf-context",
)
OKF v0.2 Bundle Serializer¶
OkfSource
¶
Bases: Struct
Provenance source descriptor declared in OKF v0.2 frontmatter.
Attributes:
| Name | Type | Description |
|---|---|---|
id | str | |
resource | str | |
title | str | Default: '' |
OkfDocument
¶
OkfBundle
¶
Bases: Struct
Collection of validated OKF v0.2 documents with directory and ZIP serialization.
from_directory
¶
from_directory(
root,
*,
exclude_specs=True,
exclude_log=True,
max_truth_lines=DEFAULT_MAX_TRUTH_LINES,
)
Load and validate an OKF v0.2 bundle from a filesystem directory.
Every loaded Markdown entry, including a reserved log.md loaded with exclude_log=False,
must fit MAX_OKF_ENTRY_BYTES; the error names the entry, its size, and the limit.
from_zip
¶
from_zip(
source,
*,
exclude_specs=False,
exclude_log=False,
max_truth_lines=DEFAULT_MAX_TRUTH_LINES,
)
Load and validate an OKF v0.2 bundle from a ZIP archive path, buffer, or stream.
Symlink, path-safety, and duplicate-path checks apply to every archive member. Members that
are not Markdown, or that exclude_specs / exclude_log filter out, are skipped before the
MAX_OKF_ENTRY_BYTES check and are never decompressed.
export_directory
¶
Write canonical bundle documents to a directory tree with safe relative paths.
export_zip
¶
Write the reproducible ZIP archive to destination and return the path.
to_zip_bytes
¶
Serialize the bundle into a reproducible DEFLATE-compressed ZIP byte buffer.
OkfValidationError
¶
Bases: VertebraError
Raised when an OKF v0.2 document, bundle, or archive fails validation.
Knowledge Catalog Clients¶
KnowledgeCatalogConfig
¶
Bases: Struct
Configuration for synchronous and asynchronous Dataplex Knowledge Catalog clients.
Attributes:
| Name | Type | Description |
|---|---|---|
project_id | str | |
location | str | Default: 'us-central1' |
entry_group_id | str | Default: DEFAULT_ENTRY_GROUP_ID |
endpoint | str | Default: DEFAULT_DATAPLEX_ENDPOINT |
quota_project_id | str | None | Default: None |
timeout_ms | int | Default: 30000 |
CatalogEntryRecord
¶
CatalogSyncSummary
¶
Bases: Struct
Summary of a progressive digest-aware OKF bundle synchronization run.
Attributes:
| Name | Type | Description |
|---|---|---|
entry_group_id | str | |
bundle_digest | str | Default: '' |
total_documents | int | Default: 0 |
created | int | Default: 0 |
updated | int | Default: 0 |
skipped | int | Default: 0 |
deleted | int | Default: 0 |
batch_count | int | Default: 0 |
batch_sizes | tuple[int, ...] | Default: () |
created_entry_ids | tuple[str, ...] | Default: () |
updated_entry_ids | tuple[str, ...] | Default: () |
skipped_entry_ids | tuple[str, ...] | Default: () |
deleted_entry_ids | tuple[str, ...] | Default: () |
CatalogSyncError
¶
Bases: VertebraError
Raised when a sync_bundle mutation fails after zero or more mutations completed.
The first failure is chained as __cause__. summary describes the mutations that completed
before the run stopped, so callers can tell which entry IDs were already written or deleted.
Attributes:
| Name | Type | Description |
|---|---|---|
summary |
| |
errors | tuple[BaseException, ...] | Every mutation failure observed in the failing batch, in batch order. |
SyncKnowledgeCatalogClient
¶
Bases: _BaseKnowledgeCatalogClient
Synchronous Google Cloud Dataplex v1 Knowledge Catalog client.
get_entry_group
¶
Fetch a Dataplex EntryGroup resource, permitting @* system entry groups.
list_entry_groups
¶
List entry groups in location and apply optional labels filtering client-side.
create_entry_group
¶
create_entry_group(
entry_group_id=None,
*,
location=None,
display_name=None,
description=None,
labels=None,
validate_only=False,
timeout_ms=None,
)
Create an RFC-1035 EntryGroup and poll the Dataplex LRO until completion.
resolve_context_set
¶
resolve_context_set(
entry_group_id=None,
*,
location=None,
display_name=None,
description=None,
labels=None,
)
Return an existing type=context-set entry group, adopt an unlabeled one, or create it.
get_entry
¶
Fetch a single Dataplex Entry, defaulting to view='ALL' so aspects hydrate.
list_entries
¶
list_entries(
*,
entry_group_id=None,
location=None,
filter_expr=None,
page_size=None,
page_token=None,
)
List all entries in an entry group across nextPageToken pages.
create_entry
¶
create_entry(
entry_id,
*,
entry_type=None,
entry_group_id=None,
location=None,
fully_qualified_name=None,
parent_entry=None,
display_name=None,
description=None,
labels=None,
aspects=None,
entry_source=None,
)
Create a Dataplex Entry inside an entry group.
update_entry
¶
update_entry(
entry_id,
*,
entry_type=None,
entry_group_id=None,
location=None,
fully_qualified_name=None,
parent_entry=None,
display_name=None,
description=None,
labels=None,
aspects=None,
entry_source=None,
update_mask=("aspects", "entrySource"),
aspect_keys=None,
allow_missing=False,
delete_missing_aspects=False,
)
Patch a Dataplex Entry with updateMask and repeated aspectKeys query parameters.
delete_entry
¶
Delete a Dataplex Entry from an entry group.
sync_bundle
¶
sync_bundle(
bundle,
*,
entry_group_id=None,
location=None,
delete_stale=False,
entry_type=None,
aspect_type=None,
)
Progressively sync an OkfBundle by SHA-256 digest in <= 250-entry batches.
With delete_stale=True, only stale entries that sync_bundle itself wrote
(CatalogEntryRecord.is_okf_managed) are deleted; entries created by other tools in the
same entry group are left untouched.
Raises:
| Type | Description |
|---|---|
CatalogSyncError
|
When a mutation fails. The original error is chained as |
search_entries
¶
search_entries(
query,
*,
entry_group_id=None,
location=None,
page_size=20,
page_token=None,
semantic_search=True,
)
Search Dataplex Universal Catalog and return the records of one result page.
The response's nextPageToken is not returned; use search_entries_page to walk
results beyond the page selected by page_token.
AsyncKnowledgeCatalogClient
¶
Bases: _BaseKnowledgeCatalogClient
Asynchronous Google Cloud Dataplex v1 Knowledge Catalog client.
get_entry_group
¶
Fetch a Dataplex EntryGroup resource, permitting @* system entry groups.
list_entry_groups
¶
List entry groups in location and apply optional labels filtering client-side.
create_entry_group
¶
create_entry_group(
entry_group_id=None,
*,
location=None,
display_name=None,
description=None,
labels=None,
validate_only=False,
timeout_ms=None,
)
Create an RFC-1035 EntryGroup and poll the Dataplex LRO until completion.
resolve_context_set
¶
resolve_context_set(
entry_group_id=None,
*,
location=None,
display_name=None,
description=None,
labels=None,
)
Return an existing type=context-set entry group, adopt an unlabeled one, or create it.
get_entry
¶
Fetch a single Dataplex Entry, defaulting to view='ALL' so aspects hydrate.
list_entries
¶
list_entries(
*,
entry_group_id=None,
location=None,
filter_expr=None,
page_size=None,
page_token=None,
)
List all entries in an entry group across nextPageToken pages.
create_entry
¶
create_entry(
entry_id,
*,
entry_type=None,
entry_group_id=None,
location=None,
fully_qualified_name=None,
parent_entry=None,
display_name=None,
description=None,
labels=None,
aspects=None,
entry_source=None,
)
Create a Dataplex Entry inside an entry group.
update_entry
¶
update_entry(
entry_id,
*,
entry_type=None,
entry_group_id=None,
location=None,
fully_qualified_name=None,
parent_entry=None,
display_name=None,
description=None,
labels=None,
aspects=None,
entry_source=None,
update_mask=("aspects", "entrySource"),
aspect_keys=None,
allow_missing=False,
delete_missing_aspects=False,
)
Patch a Dataplex Entry with updateMask and repeated aspectKeys query parameters.
delete_entry
¶
Delete a Dataplex Entry from an entry group.
sync_bundle
¶
sync_bundle(
bundle,
*,
entry_group_id=None,
location=None,
delete_stale=False,
entry_type=None,
aspect_type=None,
)
Progressively sync an OkfBundle by SHA-256 digest in <= 250-entry batches.
With delete_stale=True, only stale entries that sync_bundle itself wrote
(CatalogEntryRecord.is_okf_managed) are deleted; entries created by other tools in the
same entry group are left untouched.
Mutations of one batch run concurrently. On the first failure the remaining in-flight mutations of that batch are cancelled and awaited before the error is raised.
Raises:
| Type | Description |
|---|---|
CatalogSyncError
|
When a mutation fails. The original error is chained as |
search_entries
¶
search_entries(
query,
*,
entry_group_id=None,
location=None,
page_size=20,
page_token=None,
semantic_search=True,
)
Search Dataplex Universal Catalog and return the records of one result page.
The response's nextPageToken is not returned; use search_entries_page to walk
results beyond the page selected by page_token.