from client import CustomerEnv from models import CustomerAction def run_test(): print("🔌 Connecting to Local OpenEnv Server at http://127.0.0.1:8000...\n") # Initialize the client, then call .sync() to use it in a standard 'with' block client = CustomerEnv(base_url="http://127.0.0.1:8000") with client.sync() as env: # --- 1. RESET --- print("--- NEW EPISODE ---") result = env.reset() print(f"Customer: {result.observation.customer_reply}") print(f"Initial Reward: {result.reward}") # --- 2. STEP 1: PROBING --- print("\n--- AGENT ACTION 1: SPEAK ---") action1 = CustomerAction( action_type="speak", content="I can help with that. Could I please get your account name?" ) print(f"Agent: {action1.content}") result = env.step(action1) print(f"Customer Reply: {result.observation.customer_reply}") print(f"Reward (Should be slightly negative for turns): {result.reward}") # --- 3. STEP 2: TOOL USAGE --- print("\n--- AGENT ACTION 2: TOOL CALL ---") action2 = CustomerAction( action_type="tool_call", content="lookup_account", tool_args={"name": "John Doe"} ) print(f"Agent [Action]: Using tool '{action2.content}'") result = env.step(action2) print(f"System Response: {result.observation.tool_response}") print(f"Reward (Should increase for tool usage): {result.reward}") # --- 4. STEP 3: END CALL (Triggers Judge) --- print("\n--- AGENT ACTION 3: END EPISODE ---") action3 = CustomerAction( action_type="end_call", content="Thank you, your issue is resolved." ) result = env.step(action3) print(f"Episode Done: {result.done}") print(f"Final Step Reward: {result.reward}") print(f"Hidden Intent was: {result.observation.metadata.get('hidden_intent')}") # Print the full transcript tracked by the environment print("\n--- FULL CONVERSATION TRANSCRIPT ---") print(result.observation.conversation_history) if __name__ == "__main__": run_test()