Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.upsonic.ai/llms.txt

Use this file to discover all available pages before exploring further.

Constructor Parameters

ParameterTypeDefaultDescription
session_idstr(required)Unique identifier for this chat session
user_idstr(required)Unique identifier for the user
agentAgent(required)The Agent instance to handle conversations
storageStorageNoneStorage backend (defaults to InMemoryStorage)
full_session_memoryboolTrueStore full conversation history
summary_memoryboolFalseEnable conversation summarization
user_analysis_memoryboolFalseEnable user profile analysis
user_profile_schematypeNoneCustom Pydantic schema for user profiles
dynamic_user_profileboolFalseAuto-generate profile schema from conversations
num_last_messagesintNoneLimit history to last N messages
feed_tool_call_resultsboolFalseInclude tool calls in memory
user_memory_mode'update' | 'replace''update'How to update user profiles
debugboolFalseEnable debug logging
debug_levelint1Debug verbosity (1=standard, 2=detailed)
max_concurrent_invocationsint1Maximum concurrent invoke calls
retry_attemptsint3Number of retry attempts for failed calls
retry_delayfloat1.0Delay between retry attempts (seconds)

Instance Properties

PropertyTypeDescription
stateSessionStateCurrent session state (IDLE, AWAITING_RESPONSE, STREAMING, ERROR)
all_messagesList[ChatMessage]All messages in the session
usageAggregatedUsageRead-only view over every model call recorded for this session — tokens, cost, requests, tool calls, timing. See Metrics.
start_timefloatSession start time (Unix timestamp)
end_timefloatSession end time (None if active)
durationfloatWall-clock session duration in seconds
last_activityfloatTime since last activity in seconds
is_closedboolWhether the session is closed

Example

import asyncio
from upsonic import Agent, Chat


async def main():
    agent = Agent("anthropic/claude-sonnet-4-5")

    chat = Chat(
        session_id="session1",
        user_id="user1",
        agent=agent,
        full_session_memory=True,
        summary_memory=True,
        num_last_messages=50,
        retry_attempts=3
    )

    response = await chat.invoke("Hello!")
    print(response)

    print(f"State: {chat.state.value}")
    if chat.usage.cost is not None:
        print(f"Cost: ${chat.usage.cost:.4f}")
    print(f"Tokens: {chat.usage.total_tokens}")


if __name__ == "__main__":
    asyncio.run(main())