Skip to main content

rpaframework-sema4ai

This library enables Sema4.ai Agent API integration for RPA Framework libraries, allowing you to communicate with AI agents in your automation workflows.

Installation

pip install rpaframework-sema4ai

Requirements

  • Python 3.11 or higher

  • A Sema4.ai account with API access

  • Agent API key and endpoint URL

Features

  • Ask Agent: Send messages to AI agents and receive responses

  • Conversation Management: Create and continue conversations with agents

  • Message History: Retrieve conversation history and messages

  • Async Support: Non-blocking async methods for concurrent operations

  • Client Caching: Efficient reuse of API clients across multiple requests

Usage Examples

Robot Framework

*** Settings ***
Library    RPA.Sema4AI

*** Variables ***
${API_KEY}         %{SEMA4AI_API_KEY}
${API_ENDPOINT}    https://api.sema4.ai/v1

*** Tasks ***
Chat With Agent
    ${response}=    Ask Agent
    ...    message=What is the weather today?
    ...    agent_api_key=${API_KEY}
    ...    agent_api_endpoint=${API_ENDPOINT}
    ...    agent_name=Weather Assistant
    Log    Response: ${response.response}
    Log    Conversation ID: ${response.conversation_id}

Continue Conversation
    ${response}=    Ask Agent
    ...    message=What about tomorrow?
    ...    agent_api_key=${API_KEY}
    ...    agent_api_endpoint=${API_ENDPOINT}
    ...    agent_name=Weather Assistant
    ...    conversation_id=${PREV_CONVERSATION_ID}
    Log    Response: ${response.response}

List Conversations
    ${conversations}=    Get Conversations
    ...    agent_api_key=${API_KEY}
    ...    agent_api_endpoint=${API_ENDPOINT}
    ...    agent_name=Weather Assistant
    FOR    ${conv}    IN    @{conversations}
        Log    ${conv.name} (ID: ${conv.conversation_id})
    END

Python

from RPA.Sema4AI import Sema4AI

client = Sema4AI()

# Send a message to an agent
response = client.ask_agent(
    message="What is the weather today?",
    agent_api_key="your-api-key",
    agent_api_endpoint="https://api.sema4.ai/v1",
    agent_name="Weather Assistant"
)
print(f"Response: {response.response}")
print(f"Conversation ID: {response.conversation_id}")
print(f"Execution time: {response.execution_time}s")

# Continue the conversation
followup = client.ask_agent(
    message="What about tomorrow?",
    agent_api_key="your-api-key",
    agent_api_endpoint="https://api.sema4.ai/v1",
    agent_name="Weather Assistant",
    conversation_id=response.conversation_id
)
print(f"Follow-up: {followup.response}")

# Get all conversations for an agent
conversations = client.get_conversations(
    agent_api_key="your-api-key",
    agent_api_endpoint="https://api.sema4.ai/v1",
    agent_name="Weather Assistant"
)
for conv in conversations:
    print(f"Conversation: {conv.name} (ID: {conv.conversation_id})")

# Get messages in a conversation
messages = client.get_messages(
    agent_api_key="your-api-key",
    agent_api_endpoint="https://api.sema4.ai/v1",
    conversation_id=response.conversation_id,
    agent_name="Weather Assistant"
)
for msg in messages:
    print(f"{msg.get('role')}: {msg.get('content')}")

Async Python

For non-blocking operations in async contexts:

import asyncio
from RPA.Sema4AI import Sema4AI

async def main():
    client = Sema4AI()

    # Concurrent agent requests
    tasks = [
        client.ask_agent_async(
            message=f"Question {i}",
            agent_api_key="your-api-key",
            agent_api_endpoint="https://api.sema4.ai/v1",
            agent_name="My Assistant"
        )
        for i in range(3)
    ]
    responses = await asyncio.gather(*tasks)

    for i, response in enumerate(responses):
        print(f"Response {i}: {response.response}")

asyncio.run(main())

API Reference

Sema4AI Class

ask_agent(message, agent_api_key, agent_api_endpoint, agent_id=None, agent_name=None, conversation_id=None, conversation_name=None)

Send a message to an agent and receive a response.

  • message: The message content to send

  • agent_api_key: API key for authentication

  • agent_api_endpoint: The agent API endpoint URL

  • agent_id: Agent ID (use either agent_id or agent_name)

  • agent_name: Agent name (use either agent_id or agent_name)

  • conversation_id: Optional, for continuing existing conversations

  • conversation_name: Optional, name for new conversations

Returns: MessageResponse object with conversation_id, response, agent_name, agent_id, and execution_time

get_conversations(agent_api_key, agent_api_endpoint, agent_id=None, agent_name=None)

Get all conversations for an agent.

Returns: ConversationsResult containing list of Conversation objects

get_messages(agent_api_key, agent_api_endpoint, conversation_id, agent_id=None, agent_name=None)

Get all messages in a conversation.

Returns: MessagesResult containing list of message dictionaries

Async variants: ask_agent_async, get_conversations_async, get_messages_async

Response Objects

MessageResponse
  • conversation_id: ID of the conversation

  • response: Text response from the agent

  • agent_name: Name of the responding agent

  • agent_id: ID of the responding agent

  • execution_time: Time taken in seconds

ConversationsResult
  • conversations: List of Conversation objects

  • execution_time: Time taken in seconds

  • Supports iteration and indexing

MessagesResult
  • messages: List of message dictionaries

  • execution_time: Time taken in seconds

  • Supports iteration and indexing

Conversation
  • conversation_id: Unique conversation identifier

  • name: Conversation name

  • agent_id: ID of the associated agent

Error Handling

from RPA.Sema4AI import Sema4AI, Sema4aiException

client = Sema4AI()

try:
    response = client.ask_agent(
        message="Hello",
        agent_api_key="your-api-key",
        agent_api_endpoint="https://api.sema4.ai/v1",
        agent_name="NonExistent Agent"
    )
except Sema4aiException as e:
    print(f"Error: {e}")
    if e.status_code:
        print(f"HTTP Status: {e.status_code}")
except ValueError as e:
    print(f"Validation error: {e}")

Configuration

The library supports multiple URL formats for the API endpoint:

  • Direct API URL: https://api.sema4.ai/v1

  • Tenant URL: https://ace-xxxxx.prod-demo.sema4ai.work/tenants/GUID

  • Base URL: https://ace-xxxxx.prod-demo.sema4ai.work

All formats are automatically normalized to the correct API endpoint.

License

Apache License 2.0

Metadata

Release files for rpaframework-sema4ai 2.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for rpaframework-sema4ai 2.0.0
File Size Uploaded Provenance Actions
rpaframework_sema4ai-2.0.0.tar.gz 98.2 kB With provenance Details for rpaframework_sema4ai-2.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for rpaframework-sema4ai 2.0.0
File Interpreter ABI Platform Actions
rpaframework_sema4ai-2.0.0-py3-none-any.whl Python 3 none any Details for rpaframework_sema4ai-2.0.0-py3-none-any.whl

Total release size: 110.9 kB

Release files / rpaframework_sema4ai-2.0.0.tar.gz

Download URL rpaframework_sema4ai-2.0.0.tar.gz
Size 98.2 kB
Tags Source
SHA-256 checksum
How to use checksums
d46636f632d66d41af38412e399521480f6a75285a523b2e9cb045cb8110cc03
BLAKE2b-256 checksum
How to use checksums
0122443e60b86996cf2afe04a41b1dac3eb5788df9d11d250b92658d065623be
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 1, 2026.

Transparency log

Release files / rpaframework_sema4ai-2.0.0-py3-none-any.whl

Download URL rpaframework_sema4ai-2.0.0-py3-none-any.whl
Size 12.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dacc590c5853b09fc4c909c19b90a1645da3880e054637cc3e895fa884841f6f
BLAKE2b-256 checksum
How to use checksums
31f0a1ac7ca9ac2780c0d44932c7c0fcd612123808a1f0616697a538ee52cd1f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 1, 2026.

Transparency log

Security for rpaframework-sema4ai 2.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for rpaframework_sema4ai-2.0.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 1, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page