Reflexio Docs
API ReferenceClient Methods

Interaction Management

Methods for publishing, searching, retrieving, and deleting user interactions.

Interaction Management

publish_interaction

Publish user interactions to the system. This is the primary method for sending data to Reflexio.

response = client.publish_interaction(
    user_id,
    interactions,
    source="",
    agent_version="",
    session_id=None,
    wait_for_response=False,
    skip_aggregation=False,
    force_extraction=False,
)

Prop

Type

Returns: PublishUserInteractionResponse. In wait_for_response=False mode the response is a bare acknowledgement (success, message); in wait_for_response=True mode it also includes request_id, storage routing, and profile/playbook deltas.

Interaction Dict Fields

Prop

Type

Example 1: Basic Text Conversation

# Simple conversation (fire-and-forget)
client.publish_interaction(
    user_id="user_123",
    interactions=[
        {"role": "User", "content": "What's the weather like?"},
        {"role": "Agent", "content": "It's sunny and 72°F today."}
    ],
    source="chat",
    session_id="session_001"
)

Example 2: Wait for Confirmation

# Wait for server response
response = client.publish_interaction(
    user_id="user_123",
    interactions=[
        {"role": "User", "content": "I want to upgrade my plan"}
    ],
    source="support",
    wait_for_response=True
)

if response.success:
    print(f"Published successfully: {response.message}")

Example 3: Multi-Turn Conversation with Agent Version

# Track which agent version handled the interaction
client.publish_interaction(
    user_id="customer_456",
    interactions=[
        {"role": "User", "content": "I need help choosing a laptop"},
        {"role": "Agent", "content": "I'd be happy to help! What's your budget?"},
        {"role": "User", "content": "Around $1000 for programming work"},
        {"role": "Agent", "content": "For programming, I recommend the ThinkPad X1..."}
    ],
    source="sales_chat",
    agent_version="v2.1.0",
    session_id="purchase_flow_789"
)

Example 4: Image Interactions

import base64

def encode_image(path):
    with open(path, "rb") as f:
        return base64.b64encode(f.read()).decode("utf-8")

# User shares an image
client.publish_interaction(
    user_id="user_123",
    interactions=[
        {
            "role": "User",
            "content": "What do you think of this outfit?",
            "image_encoding": encode_image("outfit.jpg")
        },
        {
            "role": "Agent",
            "content": "Great choice! The colors complement each other well."
        }
    ],
    source="styling_consultation",
    session_id="style_session_001"
)

Example 5: Expert Content for Learning from Experts

# Provide expert ideal responses for playbook extraction
client.publish_interaction(
    user_id="user_123",
    interactions=[
        {"role": "User", "content": "What is your return policy for electronics?"},
        {
            "role": "Agent",
            "content": "You can return electronics within 30 days.",
            "expert_content": (
                "Electronics can be returned within 30 days with the original receipt. "
                "Items must be in original packaging. Opened software is final sale. "
                "Defective items have a 90-day return window."
            )
        }
    ],
    source="expert_review",
    agent_version="v1.0",
    session_id="expert_session_001"
)

Example 6: User Action Tracking

# Track user behavior on your platform
client.publish_interaction(
    user_id="shopper_789",
    interactions=[
        {
            "user_action": "CLICK",
            "user_action_description": "Clicked 'Add to Cart' for MacBook Pro",
            "interacted_image_url": "https://store.com/products/macbook-pro.jpg"
        },
        {
            "user_action": "SCROLL",
            "user_action_description": "Scrolled through laptop accessories"
        }
    ],
    source="ecommerce",
    session_id="shopping_session_001"
)

search_interactions

Search for user interactions using semantic queries.

response = client.search_interactions(
    user_id="user_123",
    query="laptop recommendations",
    top_k=5,
    most_recent_k=10
)

Prop

Type


get_interactions

Retrieve user interactions without semantic search.

response = client.get_interactions(
    user_id="user_123",
    top_k=50
)

Prop

Type


get_all_interactions

Get all user interactions across all users (admin operation).

response = client.get_all_interactions(limit=100)

Prop

Type

Returns: GetInteractionsViewResponse with interactions from all users.


delete_interaction

Delete a specific user interaction.

response = client.delete_interaction(
    user_id,
    interaction_id,
    wait_for_response=False
)

Prop

Type