Skip to main content

Python client library for interacting with the LexrChainer API

Project description

LexrChainer Client

A Python client library for interacting with the LexrChainer API.

Installation

pip install lexrchainer-client

Configuration

Configure the client using environment variables:

# API Key authentication
LEXRCHAINER_API_KEY=your_api_key

# Or JWT token authentication
LEXRCHAINER_JWT_TOKEN=your_jwt_token

# API URL (default: http://localhost:8000)
LEXRCHAINER_API_URL=http://your-api-url

Usage

1. Agent Builder Interface

Creating a Single Agent

from lexrchainer.client import AgentBuilder

# Create an agent with basic configuration
agent = (AgentBuilder("Simple Assistant")
    .with_model("gpt-4")
    .with_system_prompt("You are a helpful assistant")
    .with_description("A simple assistant for basic tasks")
    .create_agent())

# Send a message to the agent
response = agent.send_message("Hello, how are you?")

Advanced Agent Configuration

agent = (AgentBuilder("Advanced Assistant")
    .with_model("gpt-4", temperature=0.7, max_tokens=1000)  # Model with parameters
    .with_system_prompt("You are a helpful assistant")
    .with_description("An advanced assistant with multiple tools")
    .with_tool("search")  # Add a tool
    .with_tool("calculator", credentials={"api_key": "your_key"})  # Add a tool with credentials
    .with_static_meta({"version": "1.0", "category": "general"})  # Add static metadata
    .create_agent())

Custom Steps Configuration

agent = (AgentBuilder("Step-Based Assistant")
    .with_model("gpt-4")
    .add_step(
        name="Research Step",
        prompt="Research the given topic thoroughly.",
        type="HIDDEN_TURN_USER",
        flow="TO_USER",
        flow_type="AT_ONCE",
        tool_use=True
    )
    .add_step(
        name="Summary Step",
        prompt="Summarize the research findings.",
        flow_state="CONTINUE",
        response_treatment="APPEND"
    )
    .create_agent())

Managing Existing Agents

# Load an existing agent
agent = AgentBuilder("Existing Assistant").load_agent(agent_id="agent_123", conversation_id="conv_456")

# Update an existing agent
updated_agent = (AgentBuilder("Updated Assistant")
    .with_model("gpt-4")
    .with_system_prompt("New system prompt")
    .update_agent(agent_id="agent_123"))

# Get agent conversations
conversations = agent.get_agent_conversations(medium="WHATSAPP")

# Get all available agents
agents = agent.get_agents()

Creating Multiple Agents

from lexrchainer.client import MultiAgentBuilder

# Create multiple agents
multi_agent = MultiAgentBuilder()

# Configure first agent
assistant = multi_agent.add_agent("Assistant")
assistant.with_model("gpt-4").with_system_prompt("You are a helpful assistant")

# Configure second agent
expert = multi_agent.add_agent("Expert")
expert.with_model("gpt-4").with_system_prompt("You are an expert in your field")

# Create all agents and start conversation
agents = multi_agent.create_agents()

# Send a message to all agents
responses = agents.send_message("Hello everyone!")

2. Conversation API

from lexrchainer.client import ClientInterface

client = ClientInterface()

# Create a conversation
conversation = client.create_conversation({
    "medium": "WHATSAPP",
    "members": [...],
    "turn_type": "SEQUENTIAL",
    "iteration_end_criteria": "ALL_TURNS_DONE"
})

# Send a message
response = client.send_message(
    conversation_id="conv_123",
    messages=[...],
    streaming=True
)

# Add/remove members
client.add_conversation_member("conv_123", "user_456", "ACTIVE_PARTICIPATION")
client.remove_conversation_member("conv_123", "user_456")

# Get conversation messages
messages = client.get_conversation_messages("conv_123")

# Send message to specific agent
response = client.send_message_to_agent("agent_name", {
    "messages": [...],
    "streaming": True
})

# Send message to public agent
response = client.send_public_agent_message("public_agent", {
    "messages": [...],
    "streaming": True
})

3. User API

from lexrchainer.client import ClientInterface

client = ClientInterface()

# Create a user
user = client.create_user({
    "username": "john_doe",
    "email": "john@example.com",
    "phone": "+1234567890",
    "user_type": "HUMAN"
})

# Get user details
user = client.get_user("user_123")

# Update user
updated_user = client.update_user("user_123", {
    "email": "new_email@example.com"
})

# Delete user
client.delete_user("user_123")

# List users
users = client.list_users(skip=0, limit=100)

# Get current user
current_user = client.get_current_user()

4. Organization API

from lexrchainer.client import ClientInterface

client = ClientInterface()

# Create organization
org = client.create_organization({
    "name": "My Organization"
})

# Update organization
updated_org = client.update_organization("org_123", {
    "name": "Updated Organization Name"
})

5. Workspace API

from lexrchainer.client import ClientInterface

client = ClientInterface()

# Create workspace
workspace = client.create_workspace({
    "name": "My Workspace",
    "description": "A workspace for collaboration",
    "is_private": True
})

# Get workspace
workspace = client.get_workspace("workspace_123")

# Update workspace
updated_workspace = client.update_workspace("workspace_123", {
    "name": "Updated Workspace Name"
})

# Delete workspace
client.delete_workspace("workspace_123")

# List workspaces
workspaces = client.list_workspaces(skip=0, limit=100)

# Manage workspace members
members = client.list_workspace_members("workspace_123")
client.add_workspace_member("workspace_123", {
    "user_id": "user_456",
    "role": "member"
})
client.remove_workspace_member("workspace_123", "user_456")

6. Chain API

from lexrchainer.client import ClientInterface

client = ClientInterface()

# Create chain
chain = client.create_chain({
    "name": "My Chain",
    "description": "A custom chain",
    "json_content": {...}
})

# Get chain
chain = client.get_chain("chain_123")

# Update chain
updated_chain = client.update_chain("chain_123", {
    "description": "Updated description"
})

# Delete chain
client.delete_chain("chain_123")

# List chains
chains = client.list_chains(skip=0, limit=100)

# Trigger chain execution
result = client.trigger_chain("chain_123", {
    "message": "Hello",
    "meta_data": {...}
})

# Schedule chain execution
schedule = client.schedule_chain("chain_123", {
    "cron": "0 0 * * *",
    "message": "Scheduled message"
})

Features

  • Simple and intuitive API
  • Support for single and multi-agent conversations
  • Advanced tool integration with credential support
  • Custom step configuration with flow control
  • Static metadata support
  • Agent management (create, update, load)
  • Streaming responses
  • Authentication via API key or JWT token
  • Error handling and validation
  • Complete coverage of all API endpoints
  • Type hints and documentation

License

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lexrchainer_client-0.1.2.tar.gz (16.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lexrchainer_client-0.1.2-py3-none-any.whl (14.7 kB view details)

Uploaded Python 3

File details

Details for the file lexrchainer_client-0.1.2.tar.gz.

File metadata

  • Download URL: lexrchainer_client-0.1.2.tar.gz
  • Upload date:
  • Size: 16.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.0

File hashes

Hashes for lexrchainer_client-0.1.2.tar.gz
Algorithm Hash digest
SHA256 0241c9338d3a55b7355b1a73f192840ce61fe0c25de136ae35d6cdf37ae0cadb
MD5 005029fd990faa0dae3095c9874fd330
BLAKE2b-256 b58936219d230dc913d584fa70b02209c73b35a3f8bbbb808897a66b6fb2cd27

See more details on using hashes here.

File details

Details for the file lexrchainer_client-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for lexrchainer_client-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 326a2a051afc58b20e73650149fcc81a344772bd99681e76c9e99a2818a27821
MD5 c78647ba8433394799cceedd2b76dc2c
BLAKE2b-256 dfdcfe120819d7ce46b1e59892a8795b6bf2e28aa83b2bad925d9e09e3cb7db0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page