Synchronous Connection Template
The synchronous connection template provides a straightforward way to connect your agent to Snowglobe for testing. This template is ideal when your application uses standard synchronous API calls and doesn’t require complex async handling.When to Use
Use the synchronous template when:- Your agent uses synchronous API calls (like standard OpenAI client)
- You don’t need complex async operations
- You want a simple, straightforward implementation
- Your application has moderate performance requirements
Template Code
When you runsnowglobe-connect init
and select the synchronous template, Snowglobe generates this code:
Code Walkthrough
1. Imports and Setup
- CompletionRequest: Contains the messages and context from Snowglobe test scenarios
- CompletionFunctionOutputs: The response format expected by Snowglobe
- OpenAI client: Standard synchronous OpenAI client for making API calls
- Environment variable: Safely loads your OpenAI API key from environment
2. Main Function
completion
function is the entry point that Snowglobe calls for each test scenario. It must:
- Accept a
CompletionRequest
parameter - Return a
CompletionFunctionOutputs
object - Be named exactly
completion
(synchronous) oracompletion
(asynchronous)
3. Message Processing
to_openai_messages()
method converts Snowglobe’s message format to OpenAI’s expected format. You can:
- Add a system prompt to guide your agent’s behavior
- Access individual messages with
request.messages
- Extract conversation metadata with
request.get_conversation_id()
4. API Call
- Choose any OpenAI model that fits your needs
- Add additional parameters like temperature, max_tokens, etc.
- Replace with your preferred LLM provider
5. Response Formatting
CompletionFunctionOutputs
object wraps your agent’s response text.
Customization Examples
Adding Custom System Prompts
Using Different LLM Providers
Error Handling
Testing Your Implementation
-
Test the connection:
-
Start the client:
- Run scenarios: Visit your Snowglobe dashboard to execute test scenarios
Performance Considerations
The synchronous template:- ✅ Simple and straightforward to implement
- ✅ Good for moderate traffic scenarios
- ✅ Easy to debug and troubleshoot
- ⚠️ May have higher latency under heavy load
- ⚠️ Limited concurrent request handling