For the complete documentation index, see llms.txt. This page is also available as Markdown.

Document Operations

The Health Universe A2A SDK provides a powerful document client through the context.document_client property, allowing your agents to interact with documents in the current thread. This guide covers all the essential operations for working with documents.

Overview

The document client provides access to documents stored in the Health Universe platform, with support for:

  • Listing documents in the current thread

  • Reading document content (both raw and extracted text)

  • Writing new documents

  • Updating existing documents

  • Searching across documents (text and semantic search)

  • Processing status tracking for extraction pipelines

Basic Document Operations

Listing Documents

The most common operation is listing documents available in the current thread:

from health_universe_a2a import Agent, AgentContext

class DocumentProcessor(Agent):
    def get_agent_name(self) -> str:
        return "Document Processor"
    
    def get_agent_description(self) -> str:
        return "Processes and analyzes documents"
    
    async def process_message(self, message: str, context: AgentContext) -> str:
        # List all documents
        docs = await context.document_client.list_documents()
        
        # List only source documents (user uploads)
        source_docs = await context.document_client.list_documents(role="source")
        
        # List only artifacts (agent outputs)
        artifacts = await context.document_client.list_documents(role="artifact")
        
        # Include hidden documents
        all_docs = await context.document_client.list_documents(include_hidden=True)
        
        return f"Found {len(docs)} documents ({len(source_docs)} sources, {len(artifacts)} artifacts)"

Reading Document Content

Once you have documents, you can read their content in several ways:

Filtering Documents

Use the filter_by_name() method for quick document filtering:

Writing and Updating Documents

Creating New Documents

The write() method handles the complete upload process automatically:

Updating Existing Documents

Update existing documents to create new versions:

Perform keyword-based searches across document content:

Use AI-powered semantic search to find conceptually related content:

Processing Status and Waiting

Checking Processing Status

Monitor document extraction status:

Waiting for Processing

Wait for documents to be fully processed before proceeding:

Run Storage

For agents invoked via routines, the SDK provides access to run storage for ephemeral I/O operations:

Complete Example: Document Analysis Agent

Here's a comprehensive example that combines multiple document operations:

Best Practices

  1. Error Handling: Always handle cases where documents might not be ready or extraction fails:

  2. Progress Updates: Keep users informed during long document processing:

  3. Resource Management: The document client is automatically managed, but you can close it explicitly if needed:

  4. Check Document Types: Verify document types before processing:

  5. Use Run Storage for Routines: When building agents for routine workflows, leverage run storage for efficient I/O:

The document client provides a comprehensive interface for working with files in Health Universe. Whether you're building document processors, analysis tools, or data extraction agents, these operations give you the flexibility to handle various document workflows efficiently.

Last updated

Was this helpful?