Luisda
11/18/2025, 1:04 PMimport asyncio
from datetime import datetime
from google.adk.sessions import DatabaseSessionService, Session
from server.agents.baml_client.async_client import b
async def main():
# 1. Initialize ADK Session Service
session_service = DatabaseSessionService(
database_url="..."
)
# 2. Create or get a session for a user
session = await session_service.get_or_create_session(...)
# 3. Call BAML function with Guardrails
result = await b.Guardrails(
previous_messages=conversation_history,
new_message=user_message
)
# 4. Process the result
is_safe = result.is_safe
response = result.response
# 5. Update session state with the result
session.state["message_count"] = session.state.get("message_count", 0) + 1
session.state["last_message_time"] = datetime.utcnow().isoformat()
session.state["last_message_safe"] = is_safe
if not is_safe:
session.state["guardrail_violations"] = (
session.state.get("guardrail_violations", 0) + 1
)
# 6. Persist the updated session
await session_service.update_session(session)
Have you given this any thought? What is your posture concerning this use case and, more broadly, BAML integration with other frameworks?aaronv (BAML)
11/24/2025, 8:14 PMCaio Lang
11/28/2025, 6:10 PM