Environment Core

The Environment Core provides the foundational framework for creating and managing AI agent environments within the synth-ai ecosystem.

Overview

The environment system enables:
  • Agent Interaction: Structured interfaces for AI agents
  • State Management: Persistent and ephemeral state handling
  • Task Definition: Framework for defining AI tasks and objectives
  • Reproducibility: Deterministic environment execution
  • Observation/Action: Standard observation-action loops

Generated Documentation

Detailed API documentation is available for:

Core Concepts

Environment

The base environment class provides the standard interface:
from synth_ai.environments.core import Environment

class MyEnvironment(Environment):
    def reset(self):
        """Reset environment to initial state."""
        return self.get_observation()
    
    def step(self, action):
        """Execute action and return observation, reward, done."""
        # Process action
        observation = self.get_observation()
        reward = self.calculate_reward()
        done = self.is_terminal()
        
        return observation, reward, done
    
    def get_observation(self):
        """Get current environment observation."""
        return {"state": self.current_state}

Stateful Environments

For environments requiring persistent state:
from synth_ai.environments.stateful.core import StatefulEnvironment

class ChatEnvironment(StatefulEnvironment):
    def __init__(self):
        super().__init__(state_file="chat_state.json")
    
    def step(self, user_message: str):
        # Add message to conversation history
        self.state.conversation.append({
            "role": "user", 
            "content": user_message,
            "timestamp": self.current_time()
        })
        
        # Generate AI response
        response = self.generate_response(user_message)
        
        return response

Integration with Tracing

Environments automatically integrate with the tracing system:
from synth_ai.tracing_v3.session_tracer import SessionTracer

# Environment actions are automatically traced
tracer = SessionTracer()
tracer.start_session("environment-demo")

env = MyEnvironment(session_tracer=tracer)
observation = env.reset()

for step in range(10):
    action = agent.select_action(observation)
    observation, reward, done = env.step(action)
    
    if done:
        break

tracer.end_session()