Skip to main content
What this builds. A physics tutor session that receives two context lines and one question as a single batched turn. You’ll end up with. One streamed response covering all three messages — no per-message turn, no extra latency. Demonstrates batching multiple messages with send_many() so the agent processes them as a single context bundle and responds in one turn.
import asyncio

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


async def main() -> None:
    agent = Agent.new(
        name="Physics tutor",
        type=AgentType.CONVERSATIONAL,
        llm_info=LlmInfo(provider="openai", model_id="gpt-4o"),
        tools=[],
        instructions="You give concise explanations.",
        memory_config=MemoryConfig(enable_session_memory=True),
    )
    print(f"Created agent: {agent.name}")

    async with await agent.create_session() as session:
        print(f"Session connected: {session.session_id}")
        print()

        # Send multiple messages as a batch - the agent treats them as one turn

        await session.send_many(
            [
                "Context: I'm a physics student.",
                "Context: I'm preparing for an exam next week.",
                "Explain me the biology of how a human heart works. Be concise and to the point and explain with physics metaphors.",
            ]
        )

        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

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


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

Expected output

Created agent: Physics tutor
Session connected: ...

The heart works like a pump...
Done.
All three messages are consumed in a single turn — the response is one streamed answer, not three.
See Session overview for the full event taxonomy and streaming semantics.

See also

Single-turn session

Same shape but one send() instead of send_many().

Repeated sends

What happens if you call send() several times in a row.

Agent reference

Full method surface.