Skip to content

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
idstr
resourcestr
titlestr
Default: ''

OkfDocument

Bases: Struct

Parsed and validated OKF v0.2 Markdown document with canonical digest.

parse
parse(rel_path, content, *, max_truth_lines=DEFAULT_MAX_TRUTH_LINES)

Parse, normalize, validate, and digest a single OKF v0.2 Markdown document.

to_markdown
to_markdown()

Render the document as canonical UTF-8 Markdown with normalized line endings.

to_bytes
to_bytes()

Encode the canonical Markdown representation as UTF-8 bytes.

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

export_directory(root)

Write canonical bundle documents to a directory tree with safe relative paths.

export_zip

export_zip(destination)

Write the reproducible ZIP archive to destination and return the path.

to_zip_bytes

to_zip_bytes()

Serialize the bundle into a reproducible DEFLATE-compressed ZIP byte buffer.

digest

digest()

Return the deterministic 64-char SHA-256 digest across sorted bundle entries.

get

get(rel_path)

Return the document matching a relative POSIX path, or None.

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_idstr
locationstr
Default: 'us-central1'
entry_group_idstr
Default: DEFAULT_ENTRY_GROUP_ID
endpointstr
Default: DEFAULT_DATAPLEX_ENDPOINT
quota_project_idstr | None
Default: None
timeout_msint
Default: 30000

CatalogEntryRecord

Bases: Struct

Normalized Dataplex v1 catalog entry record with optional OKF digest metadata.

from_dataplex_dict
from_dataplex_dict(payload)

Construct a normalized CatalogEntryRecord from a Dataplex v1 entry dictionary.

CatalogSyncSummary

Bases: Struct

Summary of a progressive digest-aware OKF bundle synchronization run.

Attributes:

Name Type Description
entry_group_idstr
bundle_digeststr
Default: ''
total_documentsint
Default: 0
createdint
Default: 0
updatedint
Default: 0
skippedint
Default: 0
deletedint
Default: 0
batch_countint
Default: 0
batch_sizestuple[int, ...]
Default: ()
created_entry_idstuple[str, ...]
Default: ()
updated_entry_idstuple[str, ...]
Default: ()
skipped_entry_idstuple[str, ...]
Default: ()
deleted_entry_idstuple[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

CatalogSyncSummary covering only the mutations that completed.

errorstuple[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

get_entry_group(entry_group_id=None, *, location=None)

Fetch a Dataplex EntryGroup resource, permitting @* system entry groups.

list_entry_groups

list_entry_groups(*, location=None, labels=None, page_size=None)

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

get_entry(entry_id, *, entry_group_id=None, location=None, view='ALL')

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_entry(entry_id, *, entry_group_id=None, location=None)

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 __cause__ and CatalogSyncError.summary lists the entry IDs that completed before the failure.

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

get_entry_group(entry_group_id=None, *, location=None)

Fetch a Dataplex EntryGroup resource, permitting @* system entry groups.

list_entry_groups

list_entry_groups(*, location=None, labels=None, page_size=None)

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

get_entry(entry_id, *, entry_group_id=None, location=None, view='ALL')

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_entry(entry_id, *, entry_group_id=None, location=None)

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 __cause__ and CatalogSyncError.summary lists the entry IDs that completed before the failure.

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.