# Step 1: Set up the environment interactively
RESPONSE=$(curl -s -X POST https://generativelanguage.googleapis.com/v1beta/interactions \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"agent": "antigravity-preview-05-2026",
"input": "Write a basic Hello World template to /workspace/template.py.",
"environment": "remote"
}')
ENV_ID=$(echo "$RESPONSE" | python3 -c "import sys,json; print(json.load(sys.stdin)['environment_id'])")
# Step 2: Fork that environment into a named agent
curl -X POST https://generativelanguage.googleapis.com/v1beta/agents \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H "Content-Type: application/json" \
-d "{
\"id\": \"my-data-analyst\",
\"base_agent\": \"antigravity-preview-05-2026\",
\"system_instruction\": \"You are a data analyst. Use the template at /workspace/template.py for all reports.\",
\"base_environment\": \"$ENV_ID\"
}"
import uuid
from google import genai
client = genai.Client()
# Step 1: Set up the environment interactively.
interaction = client.interactions.create(
agent="antigravity-preview-05-2026",
input="Write a basic Hello World template to /workspace/template.py.",
environment="remote",
)
# Step 2: Fork that environment into a named agent.
agent_id = f"my-data-analyst-{uuid.uuid4().hex[:8]}"
agent = client.agents.create(
id=agent_id,
base_agent="antigravity-preview-05-2026",
system_instruction=(
"You are a data analyst. Use the template at /workspace/template.py"
" for all reports."
),
base_environment=interaction.environment_id,
)
print(f"Forked agent: {agent.id}")
import {GoogleGenAI} from '@google/genai';
const ai = new GoogleGenAI({});
// Step 1: Set up the environment interactively.
const interaction = await ai.interactions.create({
agent: 'antigravity-preview-05-2026',
input: 'Write a basic Hello World template to /workspace/template.py.',
environment: 'remote',
});
// Step 2: Fork that environment into a named agent.
const agentId = `my-data-analyst-${crypto.randomUUID().slice(0, 8)}`;
const agent = await ai.agents.create({
id: agentId,
base_agent: 'antigravity-preview-05-2026',
system_instruction:
'You are a data analyst. Use the template at /workspace/template.py for all reports.',
base_environment: interaction.environment_id,
});
console.log(`Forked agent: ${agent.id}`);
import com.google.genai.gaos.models.agents.Agent;
import com.google.genai.gaos.models.interactions.AgentOption;
import com.google.genai.gaos.models.agents.BaseEnvironment;
import com.google.genai.Client;
import com.google.genai.gaos.models.interactions.CreateAgentInteraction;
import com.google.genai.gaos.models.interactions.CreateAgentInteractionEnvironment;
import com.google.genai.gaos.models.operations.CreateAgentResponse;
import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;
import com.google.genai.gaos.models.operations.CreateInteractionResponse;
import com.google.genai.gaos.models.interactions.Interaction;
import com.google.genai.gaos.models.interactions.InteractionsInput;
import com.google.genai.gaos.models.interactions.Step;
Client client = new Client();
// Step 1: Set up the environment interactively.
CreateAgentInteraction params =
CreateAgentInteraction.builder()
.agent(AgentOption.of("antigravity-preview-05-2026"))
.input(
InteractionsInput.of(
"Write a basic Hello World template to /workspace/template.py."))
.environment(CreateAgentInteractionEnvironment.of("remote"))
.build();
CreateInteractionResponse interactionResponse =
client.interactions.create(CreateInteractionRequestBody.of(params));
Interaction interaction =
interactionResponse
.interaction()
.orElseThrow(() -> new RuntimeException("No interaction returned"));
// Step 2: Fork that environment into a named agent.
String agentId = "my-data-analyst-" + UUID.randomUUID().toString().substring(0, 8);
Agent agent =
Agent.builder()
.id(agentId)
.baseAgent("antigravity-preview-05-2026")
.systemInstruction(
"You are a data analyst. Use the template at /workspace/template.py for all"
+ " reports.")
.baseEnvironment(BaseEnvironment.of(interaction.environmentId().orElse("")))
.build();
CreateAgentResponse agentResponse = client.agents.create(agent);
System.out.println("Forked agent: " + agentResponse.agent().flatMap(Agent::id).orElse(""));
package main
import (
"context"
"fmt"
"log"
"time"
"google.golang.org/genai"
gaos_agents "google.golang.org/genai/interactions/models/agents"
gaos_interactions "google.golang.org/genai/interactions/models/interactions"
"google.golang.org/genai/interactions/models/operations"
)
func main() {
ctx := context.Background()
client, err := genai.NewClient(ctx, nil)
if err != nil {
log.Fatal(err)
}
// Step 1: Set up the environment interactively.
interactionReq := operations.CreateInteractionRequest{
Body: operations.NewCreateInteractionRequestBody(gaos_interactions.CreateAgentInteraction{
Agent: gaos_interactions.AgentOption("antigravity-preview-05-2026"),
Input: genai.Ptr(gaos_interactions.NewInteractionsInput("Write a basic Hello World template to /workspace/template.py.")),
Environment: genai.Ptr(gaos_interactions.NewCreateAgentInteractionEnvironment("remote")),
}),
}
interactionRes, err := client.Interactions.Create(ctx, interactionReq)
if err != nil {
log.Fatal(err)
}
envID := ""
if interactionRes.Interaction != nil && interactionRes.Interaction.EnvironmentID != nil {
envID = *interactionRes.Interaction.EnvironmentID
}
// Step 2: Fork that environment into a named agent.
agentID := fmt.Sprintf("my-data-analyst-%d", time.Now().UnixNano())
req := operations.CreateAgentRequest{
Body: gaos_agents.Agent{
ID: genai.Ptr(agentID),
BaseAgent: genai.Ptr("antigravity-preview-05-2026"),
SystemInstruction: genai.Ptr("You are a data analyst. Use the template at /workspace/template.py for all reports."),
BaseEnvironment: genai.Ptr(gaos_agents.NewBaseEnvironment(envID)),
},
}
res, err := client.Agents.Create(ctx, req)
if err != nil {
log.Fatal(err)
}
if res.Agent != nil && res.Agent.ID != nil {
fmt.Printf("Forked agent: %s\n", *res.Agent.ID)
}
}