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 sending a message with object references using the @ syntax. The SDK attaches referenced objects (KnowledgeBase, Pipeline, etc.) so the agent can use them during its response. NOTE: The references= parameter on session.send() is a v2 feature. This example shows the intended API shape. In v1, references are not yet supported and this will raise an error.
import asyncio

from vectorshift import KnowledgeBase, Pipeline
from vectorshift.agent import Agent, AgentType, LlmInfo, MemoryConfig
from vectorshift.events import SessionEventType


async def main() -> None:
    agent = Agent.new(
        name="Docs analyst",
        type=AgentType.CONVERSATIONAL,
        llm_info=LlmInfo(provider="openai", model_id="gpt-4o"),
        tools=[],
        instructions="You use provided context and tools faithfully.",
        memory_config=MemoryConfig(enable_session_memory=True),
    )

    # Fetch existing objects to reference
    _kb = KnowledgeBase.fetch(name="Company Docs")  # noqa: F841
    _pipeline = Pipeline.fetch(name="Analyzer")  # noqa: F841

    async with await agent.create_session() as session:
        # v2: pass references so the agent can use @docs and @analyzer
        # In v1, this parameter is not yet supported.
        await session.send(
            "Search @docs for Q3 revenue, then run @analyzer on the best paragraph.",
            # references={      # v2 only
            #     "docs": kb,
            #     "analyzer": pipeline,
            # },
        )

        print("Assistant: ", 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()

    agent.delete()
    print("\nDone.")


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