Core environment system for AI agents
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}
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
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()