Skip to main content

Documentation Index

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

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

Demonstrates that the same Session class works for chatbots, providing a unified real-time experience across both agents and chatbots.
import asyncio

from vectorshift import Chatbot
from vectorshift.events import SessionEventType


async def main() -> None:
    # Fetch an existing chatbot (must already exist)
    chatbot = Chatbot.fetch(name="My Chatbot")
    print(f"Fetched chatbot: {chatbot.name} (id={chatbot.id})")

    # Open a session - same API as agent.create_session()
    async with await chatbot.create_session() as session:
        print(f"Session connected: {session.session_id}")

        await session.send("Hello! What can you help me with?")

        print("\nAssistant: ", end="", flush=True)
        async for event in session.listen(
            event_types=[
                SessionEventType.MESSAGE_DELTA,
                SessionEventType.MESSAGE_COMPLETE,
            ]
        ):
            if event.delta:
                print(event.delta, end="", flush=True)
            if event.is_complete:
                break
        print()

    print("\nDone.")


if __name__ == "__main__":
    asyncio.run(main())
Source: examples/agents/11_chatbot_session.py in the SDK repo.