Skip to main content

1. Setup clients

Initialize Freeplay and Google GenAI client SDKs.

2. Manage chat history

Maintain a running messages list across turns. Pass previous messages as history when fetching the formatted prompt so the model has full conversation context.

3. Fetch prompt from Freeplay

Pull in the formatted prompt with Freeplay. The prompt contains the system instruction and model parameters.

4. Call Google GenAI with the tools

When creating a new completion, pass in the tools configuration and formatted prompt contents.

5. Handle tool call

When the model responds with a function call, execute the external function in your service. As an example here, we are calling get_current_temperature function. Append both the function call and the function response to the messages list to maintain history.

6. Record to Freeplay

Pass in the completion response and messages to capture the tool call, its result, and the full conversation history.

Examples