Session
This chapter describes the concept of a session.
Idea
A Session
in the Maia Framework is used for grouping agents into different communication channels. For simple agentic systems, you will probably use only one session, as all agents can talk to each other freely.
Session
is also used for grouping validators and assertions. Thanks to this concept, you can establish different channels that will check different things. Finally, you can mix everything: many sessions, many agents, and many assertions and validators.
In the future, session
will get more functionality.
Usage in tests
Create session
To test any communication between agents or users, you first need to create a session.
The creation of a session can be done in two places: in the setup phase or in each test.
Setup phase
class TestContentAssertions(MaiaTest):
def setup_agents(self):
self.create_agent(
name="Alice",
provider=self.get_provider("ollama"),
system_message="You are a helpful AI assistant. You will follow user instructions precisely."
)
def setup_session(self):
self.create_session(
assertions=[assert_professional_tone, assert_no_hallucination_markers],
session_id="common_session"
)
In test
@pytest.mark.asyncio
async def test_conversation_direct_message(self):
# In this test, we configure agents without the ignore prompt
# and send messages directly to them.
self.create_agent(
name="Alice",
provider=GenericLiteLLMProvider(config={
"model": "ollama/mistral",
"api_base": "http://localhost:11434"
}),
system_message="You are a weather assistant."
)
self.create_agent(
name="Bob",
provider=GenericLiteLLMProvider(config={
"model": "ollama/mistral",
"api_base": "http://localhost:11434"
}),
system_message="You are an assistant who only suggests clothing."
)
session = self.create_session(
["Alice", "Bob"],
assertions=[assert_professional_tone],
)
You can assign a custom ID to a session (if not assigned, one will be generated). This is useful when you want to extend a session or easily locate it in the dashboard.
Extend session
If you have one configuration that you would like to reuse in many tests, you can create a session in the setup phase and extend it. Thanks to this, you do not need to repeat the creation of the session.
Extending a session is very simple:
class TestContentAssertions(MaiaTest):
def setup_agents(self):
self.create_agent(
name="Alice",
provider=self.get_provider("ollama"),
system_message="You are a helpful AI assistant. You will follow user instructions precisely."
)
def setup_session(self):
self.create_session(
assertions=[assert_professional_tone, assert_no_hallucination_markers],
session_id="common_session"
)
@pytest.mark.asyncio
async def test_professional_tone_assertion(self):
session = self.extend_session("common_session", agent_names=["Alice"])
await session.user_says("Tell me the weather and end your response with the word 'lol'.")
with pytest.raises(MaiaAssertionError, match=r"Unprofessional language detected: .*"):
await session.agent_responds("Alice")
We are using the session id
to figure out which session needs to be extended.