From d6b7f87b05195dc0f1340ddd9ca28089923b5a32 Mon Sep 17 00:00:00 2001 From: bb220 Date: Tue, 19 May 2026 11:29:09 -0400 Subject: [PATCH] Remove unused test scripts --- TESTING_INSTRUCTIONS.md | 113 ----- integration_tests/README.md | 62 --- .../test_concentrate_with_run.py | 18 - integration_tests/test_exa_with_run.py | 17 - integration_tests/test_xai_with_run.py | 18 - testing/README.md | 54 --- testing/test_docs_exact_code.py | 269 ------------ testing/test_multi_turn_chat.py | 388 ------------------ testing/test_multi_turn_chat_simple.py | 150 ------- testing/test_multi_turn_loop.py | 213 ---------- testing/test_multi_turn_with_tools.py | 261 ------------ testing/test_tool_debug.py | 98 ----- 12 files changed, 1661 deletions(-) delete mode 100644 TESTING_INSTRUCTIONS.md delete mode 100644 integration_tests/README.md delete mode 100644 integration_tests/test_concentrate_with_run.py delete mode 100644 integration_tests/test_exa_with_run.py delete mode 100644 integration_tests/test_xai_with_run.py delete mode 100644 testing/README.md delete mode 100644 testing/test_docs_exact_code.py delete mode 100644 testing/test_multi_turn_chat.py delete mode 100644 testing/test_multi_turn_chat_simple.py delete mode 100644 testing/test_multi_turn_loop.py delete mode 100644 testing/test_multi_turn_with_tools.py delete mode 100644 testing/test_tool_debug.py diff --git a/TESTING_INSTRUCTIONS.md b/TESTING_INSTRUCTIONS.md deleted file mode 100644 index 5d4a187..0000000 --- a/TESTING_INSTRUCTIONS.md +++ /dev/null @@ -1,113 +0,0 @@ -# Testing Instructions for Documentation Examples - -This document provides instructions for testing code examples in the PromptLayer documentation. - -## Test Workspace - -We maintain a dedicated test workspace for documentation examples with pre-configured prompts and settings. - -### Workspace Details -- **Purpose**: Testing documentation code examples -- **API Key**: Available in secure storage (not committed to repo) -- **Workspace ID**: Contact team for access - -## Testing Multi-Turn Chat Examples - -### Required Prompts - -To test the multi-turn chat examples from the documentation, you only need TWO prompts set up in your workspace: - -1. **multi-turn-assistant** - - Type: Chat prompt template - - Required placeholders: - - `{{chat_history}}` - Message placeholder for conversation history - - `{{user_question}}` - Text variable for current user input - - `{{ai_in_progress}}` - Array variable for tool call tracking (can be empty list if not using tools) - - Example system message: "You are a helpful assistant. Use the conversation history to maintain context." - - Used for: Basic multi-turn conversations, context retention tests, and examples without tools - -2. **multi-turn-assistant-with-tools** (Optional - only if testing tool functionality) - - Type: Chat prompt template - - Required placeholders (in this order): - - `{{chat_history}}` - Message placeholder for conversation history - - `{{user_question}}` - Text variable for current user input - - `{{ai_in_progress}}` - Message placeholder for tool interaction messages (MUST come AFTER user_question) - - `{{user_context}}` - Object variable for additional context (optional) - - Important: The order matters! `ai_in_progress` must come after `user_question` because it contains the AI's tool interactions in response to the user's question - - Tool definitions (if testing tools): - - `search_kb` - Search knowledge base - - `create_ticket` - Create support ticket - - `escalate` - Escalate to human agent - - `end_conversation` - End the conversation - - Used for: Examples demonstrating tool usage in multi-turn conversations - -### Running Tests - -1. Install dependencies: -```bash -pip install promptlayer python-dotenv -``` - -2. Set your API key: - - Copy `.env.example` to `.env` - - Add your PromptLayer API key to the `.env` file: - ``` - PROMPTLAYER_API_KEY=your_api_key_here - ``` - -3. Run the test scripts: -```bash -# Run all basic tests -python testing/test_multi_turn_chat.py - -# Run simplified sanity checks -python testing/test_multi_turn_chat_simple.py - -# Run multi-turn conversation loop test (3+ turns) -python testing/test_multi_turn_loop.py - -# Run tool conversation test -python testing/test_multi_turn_with_tools.py - -# Debug tool interactions -python testing/test_tool_debug.py -``` - -### Test Script Locations - -All test scripts are located in the `testing/` folder: - -- **`test_multi_turn_chat.py`** - Main test suite with all examples from documentation -- **`test_multi_turn_chat_simple.py`** - Quick sanity checks without loops -- **`test_multi_turn_loop.py`** - Tests multiple conversation turns (3+) with context retention -- **`test_multi_turn_with_tools.py`** - Demonstrates proper tool handling with ai_in_progress -- **`test_tool_debug.py`** - Debug script to understand tool conversation flow - -## Adding New Test Prompts - -When adding new documentation examples that require testing: - -1. Create the prompt template in the test workspace -2. Document the required placeholders and configuration here -3. Add corresponding test cases to the test script -4. Verify all examples work before publishing documentation - -## Troubleshooting - -### Common Issues - -1. **Missing placeholders**: Ensure all required placeholders are defined in your prompt template -2. **API key errors**: Verify your API key has access to the test workspace -3. **Tool call errors**: Check that tool definitions match the expected format in the documentation - -### Debug Mode - -Enable debug output by setting: -```python -import logging -logging.basicConfig(level=logging.DEBUG) -``` - -## Contact - -For access to the test workspace or assistance with testing, contact the PromptLayer team. \ No newline at end of file diff --git a/integration_tests/README.md b/integration_tests/README.md deleted file mode 100644 index 05aacc6..0000000 --- a/integration_tests/README.md +++ /dev/null @@ -1,62 +0,0 @@ -# Integration Tests - -**DO NOT COMMIT THIS FOLDER** - -## Testing Philosophy - -When testing custom provider integrations (Exa, xAI, etc.), **always use `promptlayer.run()`** with prompt templates from the PromptLayer dashboard. - -### Why promptlayer.run()? - -1. **Tests the full integration** - Dashboard → SDK → Provider -2. **Validates logging** - Ensures requests are properly tracked in PromptLayer -3. **Mirrors production usage** - This is how users will actually use the integrations -4. **Tests prompt templates** - Confirms custom providers work with the Prompt Registry - -### Don't Use Direct SDK Calls - -Avoid testing with direct LLM client calls that bypass PromptLayer. Instead, always use `promptlayer.run()` which tests the full integration flow through the prompt template system. - -## Setup Requirements - -Before running tests: -1. Set up the custom provider in PromptLayer dashboard (Settings → Custom Providers and Models) -2. Create a prompt template that uses the custom provider -3. Create `api_keys.py` in this folder with your API keys (see format below) - -### API Keys Format - -Create `integration_tests/api_keys.py`: -```python -API_KEYS = { - "promptlayer": "pl_****", - "exa": "****", - "xai": "xai-****", - "concentrate": "****", -} -``` - -**Note:** `api_keys.py` is gitignored and should NOT be committed. - -## Test Files - -- `test_exa_with_run.py` - Tests Exa integration via promptlayer.run() -- `test_xai_with_run.py` - Tests xAI (Grok) integration via promptlayer.run() -- `test_concentrate_with_run.py` - Tests Concentrate AI integration via promptlayer.run() - -## Running Tests - -```bash -# From repo root -python integration_tests/test_exa_with_run.py -python integration_tests/test_xai_with_run.py -python integration_tests/test_concentrate_with_run.py -``` - -## Expected Output - -Successful tests should: -- Print the AI response -- Return a `request_id` (confirms logging to PromptLayer) -- Include `prompt_blueprint` data showing the template used - diff --git a/integration_tests/test_concentrate_with_run.py b/integration_tests/test_concentrate_with_run.py deleted file mode 100644 index c9bff93..0000000 --- a/integration_tests/test_concentrate_with_run.py +++ /dev/null @@ -1,18 +0,0 @@ -from promptlayer import PromptLayer -from api_keys import API_KEYS - -promptlayer = PromptLayer(api_key=API_KEYS["promptlayer"]) - -# Run a prompt template that uses your Concentrate custom provider -# (Your template should be configured to use a Concentrate model like -# claude-opus-4-7, gpt-5.5, or anthropic/claude-opus-4-7) -response = promptlayer.run( - prompt_name="concentrate-test", - input_variables={"topic": "prompt engineering"} -) - -# Access the response (template is configured for the Responses API) -print(response["raw_response"].output_text) - -# The request is automatically logged with request_id -print(f"\nRequest ID: {response['request_id']}") diff --git a/integration_tests/test_exa_with_run.py b/integration_tests/test_exa_with_run.py deleted file mode 100644 index 31b0ae0..0000000 --- a/integration_tests/test_exa_with_run.py +++ /dev/null @@ -1,17 +0,0 @@ -from promptlayer import PromptLayer -from api_keys import API_KEYS - -promptlayer = PromptLayer(api_key=API_KEYS["promptlayer"]) - -# Run a prompt template that uses your Exa custom provider -response = promptlayer.run( - prompt_name="exa-test", - input_variables={"name": "Jared Zoneraich"} -) - -# Access the response -print(response["raw_response"].choices[0].message.content) - -# The request is automatically logged with request_id -print(f"\nRequest ID: {response['request_id']}") - diff --git a/integration_tests/test_xai_with_run.py b/integration_tests/test_xai_with_run.py deleted file mode 100644 index 7f1ee1c..0000000 --- a/integration_tests/test_xai_with_run.py +++ /dev/null @@ -1,18 +0,0 @@ -from promptlayer import PromptLayer -from api_keys import API_KEYS - -promptlayer = PromptLayer(api_key=API_KEYS["promptlayer"]) - -# Run a prompt template that uses your xAI custom provider -# (Your template should be configured to use a Grok model like grok-4-fast-reasoning) -response = promptlayer.run( - prompt_name="grok-test", - input_variables={"topic": "prompt engineering"} -) - -# Access the response -print(response["raw_response"].choices[0].message.content) - -# The request is automatically logged with request_id -print(f"\nRequest ID: {response['request_id']}") - diff --git a/testing/README.md b/testing/README.md deleted file mode 100644 index d1c472b..0000000 --- a/testing/README.md +++ /dev/null @@ -1,54 +0,0 @@ -# Testing Suite for PromptLayer Documentation - -This folder contains test scripts for validating code examples in the PromptLayer documentation. - -## Quick Start - -1. Ensure you have `.env` configured in the parent directory with: - ``` - PROMPTLAYER_API_KEY=your_api_key_here - OPENAI_API_KEY=your_openai_key_here # If using OpenAI models - ANTHROPIC_API_KEY=your_anthropic_key_here # If using Anthropic models - ``` - -2. Install dependencies: - ```bash - pip install promptlayer python-dotenv - ``` - -3. Run tests: - ```bash - python testing/test_multi_turn_chat_simple.py # Quick sanity check - ``` - -## Test Files - -### Core Tests -- **`test_multi_turn_chat.py`** - Complete test suite from documentation examples -- **`test_multi_turn_chat_simple.py`** - Quick validation without loops - -### Advanced Tests -- **`test_multi_turn_loop.py`** - Multi-turn conversation with 3+ exchanges -- **`test_multi_turn_with_tools.py`** - Tool handling with ai_in_progress -- **`test_tool_debug.py`** - Debug tool conversation flow - -## Required Prompts - -The tests require these prompts in your PromptLayer workspace: - -1. **multi-turn-assistant** - Basic conversation prompt - - Placeholders: `{{chat_history}}`, `{{user_question}}` - -2. **multi-turn-assistant-with-tools** - Tool-enabled prompt - - Placeholders: `{{chat_history}}`, `{{user_question}}`, `{{ai_in_progress}}` - - Tools: search_kb, create_ticket, escalate, end_conversation - -See `TESTING_INSTRUCTIONS.md` in the parent directory for detailed setup. - -## Adding New Tests - -When adding tests: -1. Follow the existing naming convention: `test_[feature].py` -2. Include docstrings explaining what's being tested -3. Add the test to this README and TESTING_INSTRUCTIONS.md -4. Ensure tests can run independently \ No newline at end of file diff --git a/testing/test_docs_exact_code.py b/testing/test_docs_exact_code.py deleted file mode 100644 index 170e14c..0000000 --- a/testing/test_docs_exact_code.py +++ /dev/null @@ -1,269 +0,0 @@ -""" -Test script using EXACT code from the documentation. -This ensures users can copy-paste the code and it will work. -""" - -import os -from typing import Any, Dict -from promptlayer import PromptLayer -from dotenv import load_dotenv - -# Load environment variables from .env file -load_dotenv() - -# Configuration -API_KEY = os.environ.get('PROMPTLAYER_API_KEY') -if not API_KEY: - raise ValueError("PROMPTLAYER_API_KEY not found in environment variables.") - -# Initialize client -promptlayer_client = PromptLayer(api_key=API_KEY) - -# Mock function for getting next user input (stops the loop) -def get_next_user_input(): - """Mock function - returns None to exit loop after one turn""" - return None - -# Mock function for executing tools -def execute_tool(tool_call): - """Mock tool execution""" - if isinstance(tool_call, dict): - tool_name = tool_call.get("function", {}).get("name", "unknown") - else: - tool_name = "unknown" - return f"Mock result for tool: {tool_name}" - -# ============================================================ -# EXACT CODE FROM DOCUMENTATION - Basic Conversation -# ============================================================ - -def run_conversation(user_question): - chat_history = [] - - while True: - # For basic prompts without tools - result = promptlayer_client.run( - prompt_name="multi-turn-assistant", - input_variables={ - "user_question": user_question, - "chat_history": chat_history - }, - tags=["multi-turn-chat"] - ) - - # Extract the assistant's last message - last_message = result["prompt_blueprint"]["prompt_template"]["messages"][-1] - - # Add to conversation history - chat_history.append({ - "role": "user", - "content": [{"type": "text", "text": user_question}] - }) - chat_history.append(last_message) - - # Get next user input - user_question = get_next_user_input() - if not user_question: - break - - return last_message if 'last_message' in locals() else None - -# ============================================================ -# EXACT CODE FROM DOCUMENTATION - Conversation with Tools -# ============================================================ - -def run_conversation_with_tools(user_question): - chat_history = [] - ai_in_progress = [] # Messages from AI's tool interactions - - while True: - # With tools, include ai_in_progress for multi-step operations - result = promptlayer_client.run( - prompt_name="multi-turn-assistant-with-tools", - input_variables={ - "chat_history": chat_history, - "user_question": user_question, - "ai_in_progress": ai_in_progress # [AI call, tool response, AI call, tool response, ...] - }, - tags=["multi-turn-chat"] - ) - - last_message = result["prompt_blueprint"]["prompt_template"]["messages"][-1] - - # Check if conversation should end - function_call = last_message.get("function_call") - if function_call and function_call.get("name") == "end_conversation": - return last_message if 'last_message' in locals() else None - - # Handle tool calls - AI might need multiple tool calls before responding - if last_message.get("tool_calls") or last_message.get("function_call"): - # Add AI's message with tool call to ai_in_progress - ai_in_progress.append(last_message) - - # Execute tool and add response - if last_message.get("tool_calls"): - for tool_call in last_message["tool_calls"]: - tool_result = execute_tool(tool_call) - ai_in_progress.append({ - "role": "tool", - "content": [{"type": "text", "text": str(tool_result)}], - "tool_call_id": tool_call["id"] - }) - elif last_message.get("function_call"): - tool_result = execute_tool(last_message["function_call"]) - ai_in_progress.append({ - "role": "function", - "name": last_message["function_call"]["name"], - "content": str(tool_result) - }) - # Loop continues - AI can make another tool call or respond to user - else: - # AI provided final response - add everything to history - chat_history.append({ - "role": "user", - "content": [{"type": "text", "text": user_question}] - }) - - # Add any tool interactions from ai_in_progress to history - if ai_in_progress: - chat_history.extend(ai_in_progress) - - # Add final response - chat_history.append(last_message) - - # Clear ai_in_progress for next user turn - ai_in_progress = [] - - # Get next user input - user_question = get_next_user_input() - if not user_question: - break - - return last_message if 'last_message' in locals() else None - -# ============================================================ -# TEST FUNCTIONS -# ============================================================ - -def test_basic_conversation(): - """Test the exact basic conversation code from docs""" - print("\n1. Testing EXACT basic conversation code from docs...") - - try: - result = run_conversation("Hello, how are you?") - - if result: - text = result.get('content', [{}])[0].get('text', 'No response') - print(f"✅ Basic conversation works! Response: {text[:50]}...") - return True - else: - print("❌ No result returned") - return False - except Exception as e: - print(f"❌ Error: {e}") - return False - -def test_conversation_with_tools(): - """Test the exact tool conversation code from docs""" - print("\n2. Testing EXACT tool conversation code from docs...") - - try: - result = run_conversation_with_tools("I need help with my password") - - if result: - text = result.get('content', [{}])[0].get('text', 'No response') - print(f"✅ Tool conversation works! Response: {text[:50]}...") - return True - else: - print("❌ No result returned") - return False - except Exception as e: - print(f"❌ Error: {e}") - return False - -def test_conversation_with_history(): - """Test with pre-existing history using exact doc code""" - print("\n3. Testing with conversation history...") - - # This simulates what would happen after multiple turns - # We'll modify the function slightly to accept initial history - def run_conversation_with_history(user_question, initial_history): - chat_history = initial_history # Use provided history - - # Single turn only for testing - result = promptlayer_client.run( - prompt_name="multi-turn-assistant", - input_variables={ - "user_question": user_question, - "chat_history": chat_history - }, - tags=["multi-turn-chat"] - ) - - if result: - last_message = result["prompt_blueprint"]["prompt_template"]["messages"][-1] - return last_message - return None - - # Pre-existing conversation - history = [ - { - "role": "user", - "content": [{"type": "text", "text": "I'm visiting New York next week"}] - }, - { - "role": "assistant", - "content": [{"type": "text", "text": "That sounds exciting! NYC has so much to offer."}] - } - ] - - try: - result = run_conversation_with_history("What's the weather like there?", history) - - if result: - text = result.get('content', [{}])[0].get('text', 'No response') - print(f"✅ History retention works! Response: {text[:50]}...") - return True - else: - print("❌ No result returned") - return False - except Exception as e: - print(f"❌ Error: {e}") - return False - -def main(): - """Run all tests using EXACT documentation code""" - print("=" * 60) - print("TESTING EXACT CODE FROM DOCUMENTATION") - print("=" * 60) - print("This test uses the EXACT code snippets from the docs") - print("to ensure copy-paste compatibility.") - - results = [] - - # Test basic conversation - results.append(test_basic_conversation()) - - # Test tool conversation - results.append(test_conversation_with_tools()) - - # Test with history - results.append(test_conversation_with_history()) - - # Summary - print("\n" + "=" * 60) - passed = sum(results) - total = len(results) - - if passed == total: - print(f"✅ SUCCESS: All {total} tests passed!") - print("Documentation code is copy-paste ready!") - else: - print(f"⚠️ WARNING: {total - passed} test(s) failed") - print("Documentation code may need updates") - - return passed == total - -if __name__ == "__main__": - success = main() - exit(0 if success else 1) \ No newline at end of file diff --git a/testing/test_multi_turn_chat.py b/testing/test_multi_turn_chat.py deleted file mode 100644 index 8248d63..0000000 --- a/testing/test_multi_turn_chat.py +++ /dev/null @@ -1,388 +0,0 @@ -""" -Test script for Multi-Turn Chat documentation examples. -This script tests the code examples from the Multi-Turn Chat documentation page. - -Prerequisites: -1. Set PROMPTLAYER_API_KEY environment variable -2. Create the following prompts in your PromptLayer workspace: - - "multi-turn-assistant" (basic chat) - - "multi-turn-assistant-with-tools" (chat with tools) - -See TESTING_INSTRUCTIONS.md for detailed setup instructions. -""" - -import os -from typing import Any, Dict, List, Optional -from promptlayer import PromptLayer -from dotenv import load_dotenv - -# Load environment variables from .env file -load_dotenv() - -# Configuration -API_KEY = os.environ.get('PROMPTLAYER_API_KEY') -if not API_KEY: - raise ValueError("PROMPTLAYER_API_KEY not found in environment variables. Please set it in .env file.") - -# Initialize client -promptlayer_client = PromptLayer(api_key=API_KEY) - -print(f"Using API key: {API_KEY[:10]}...") -print(f"PromptLayer version: {promptlayer_client.__class__.__module__}") - - -def execute_tool(tool_call: Dict[str, Any]) -> Any: - """Mock tool execution for testing.""" - tool_name = tool_call.get("function", {}).get("name", "") - - if tool_name == "search_kb": - return {"results": ["Article about password reset", "FAQ about billing"]} - elif tool_name == "create_ticket": - return {"ticket_id": "TICKET-12345", "status": "created"} - elif tool_name == "escalate": - return {"escalated": True, "agent": "human_support"} - elif tool_name == "get_weather": - return {"temperature": "72°F", "conditions": "sunny"} - else: - return {"error": f"Unknown tool: {tool_name}"} - - -def get_next_user_input() -> Optional[str]: - """Get next user input - for testing, we'll return None to end conversation.""" - return None # End conversation after first exchange - - -def run_conversation(user_question: str) -> Dict[str, Any]: - """ - Main conversation loop from the documentation. - This is the exact code from the Implementation Pattern section. - """ - chat_history = [] - - while True: - # For basic prompts without tools - result = promptlayer_client.run( - prompt_name="multi-turn-assistant", - input_variables={ - "user_question": user_question, - "chat_history": chat_history or [], - "ai_in_progress": [] # Default to empty list - }, - tags=["multi-turn-chat"] - ) - - # Extract the assistant's last message - last_message = result["prompt_blueprint"]["prompt_template"]["messages"][-1] - - # Check if conversation should end - function_call = last_message.get("function_call") - if function_call and function_call.get("name") == "end_conversation": - return last_message if 'last_message' in locals() else None - - # Add to conversation history - chat_history.append({ - "role": "user", - "content": [{"type": "text", "text": user_question}] - }) - chat_history.append(last_message) - - # Get next user input - user_question = get_next_user_input() - if not user_question: - break - - return last_message if 'last_message' in locals() else None - - -def run_conversation_with_tools(user_question: str) -> Dict[str, Any]: - """ - Conversation loop with tool support from the documentation. - This demonstrates proper ai_in_progress usage for tool interactions. - """ - chat_history = [] - ai_in_progress = [] # Messages from AI's tool interactions - - while True: - # With tools, include ai_in_progress for multi-step operations - result = promptlayer_client.run( - prompt_name="multi-turn-assistant-with-tools", - input_variables={ - "chat_history": chat_history or [], - "user_question": user_question, - "ai_in_progress": ai_in_progress or [] # [AI call, tool response, AI call, tool response, ...] - }, - tags=["multi-turn-chat"] - ) - - last_message = result["prompt_blueprint"]["prompt_template"]["messages"][-1] - - # Check if conversation should end - function_call = last_message.get("function_call") - if function_call and function_call.get("name") == "end_conversation": - return last_message if 'last_message' in locals() else None - - # Handle tool calls - AI might need multiple tool calls before responding - if last_message.get("tool_calls") or last_message.get("function_call"): - # Add AI's message with tool call to ai_in_progress - ai_in_progress.append(last_message) - - # Execute tool and add response - if last_message.get("tool_calls"): - for tool_call in last_message["tool_calls"]: - tool_result = execute_tool(tool_call) - ai_in_progress.append({ - "role": "tool", - "content": [{"type": "text", "text": str(tool_result)}], - "tool_call_id": tool_call["id"] - }) - elif last_message.get("function_call"): - tool_result = execute_tool(last_message["function_call"]) - ai_in_progress.append({ - "role": "function", - "name": last_message["function_call"]["name"], - "content": str(tool_result) - }) - # Loop continues - AI can make another tool call or respond to user - else: - # AI provided final response - add everything to history - chat_history.append({ - "role": "user", - "content": [{"type": "text", "text": user_question}] - }) - - # Add any tool interactions from ai_in_progress to history - if ai_in_progress: - chat_history.extend(ai_in_progress) - - # Add final response - chat_history.append(last_message) - - # Clear ai_in_progress for next user turn - ai_in_progress = [] - - # Get next user input - user_question = get_next_user_input() - if not user_question: - break - - return last_message if 'last_message' in locals() else None - - -def test_context_retention(): - """ - Test function from the documentation. - Tests how the assistant retains context from conversation history. - """ - test_history = [ - { - "role": "user", - "content": [{"type": "text", "text": "I'm in New York"}] - }, - { - "role": "assistant", - "content": [{"type": "text", "text": "Got it, you're in New York. How can I help you?"}] - } - ] - - result = promptlayer_client.run( - prompt_name="multi-turn-assistant", - input_variables={ - "chat_history": test_history, - "user_question": "What's the weather like?", - "ai_in_progress": [] # Default to empty list - } - ) - - last_message = result["prompt_blueprint"]["prompt_template"]["messages"][-1] - # Assistant should reference New York from context - assert "New York" in last_message["content"][0]["text"] - print("✓ Context retention test passed") - return last_message if 'last_message' in locals() else None - - -def test_message_placeholder_example(): - """Test the message placeholder example from the documentation.""" - result = promptlayer_client.run( - prompt_name="multi-turn-assistant", - input_variables={ - "chat_history": [ - { - "role": "user", - "content": [{"type": "text", "text": "What's the weather?"}] - }, - { - "role": "assistant", - "content": [{"type": "text", "text": "I'll check the weather for you."}] - } - ], - "user_question": "How about tomorrow?", - "ai_in_progress": [] # Default to empty list - } - ) - - print("✓ Message placeholder example executed successfully") - return result - - -class StatelessToolAgent: - """Tool-Enabled Assistant example from the documentation.""" - - def __init__(self, promptlayer_client): - self.client = promptlayer_client - self.max_turns = 20 - - def get_user_context(self) -> Dict[str, Any]: - """Mock user context for testing.""" - return { - "user_id": "user_123", - "account_type": "premium", - "previous_tickets": 2 - } - - def get_next_user_input(self) -> Optional[str]: - """For testing, return None to end conversation.""" - return None - - def execute_tool(self, tool_call: Dict[str, Any]) -> Any: - """Execute tools for support agent.""" - return execute_tool(tool_call) - - def format_final_response(self, last_message: Dict[str, Any]) -> Dict[str, Any]: - """Format the final response.""" - return { - "status": "conversation_ended", - "final_message": last_message - } - - def handle_max_turns_reached(self, chat_history: List[Dict[str, Any]]) -> Dict[str, Any]: - """Handle case when max turns is reached.""" - return { - "status": "max_turns_reached", - "history_length": len(chat_history) - } - - def run_conversation(self, initial_question: str) -> Dict[str, Any]: - """ - Run the support conversation. - This is the exact code from the Example section. - """ - chat_history = [] - ai_in_progress = [] - user_question = initial_question - turn_count = 0 - - while turn_count < self.max_turns: - # Run stateless turn - result = self.client.run( - prompt_name="multi-turn-assistant-with-tools", - input_variables={ - "chat_history": chat_history or [], - "user_question": user_question, - "ai_in_progress": ai_in_progress or [], # After user_question, contains tool interactions - "user_context": self.get_user_context() - }, - tags=["support", "multi-turn"] - ) - - # Extract assistant's response - last_message = result["prompt_blueprint"]["prompt_template"]["messages"][-1] - - # Check for conversation end - if last_message.get("function_call", {}).get("name") == "end_conversation": - return self.format_final_response(last_message) - - # Handle tool calls - if last_message.get("tool_calls"): - tool_results = [] - for tool_call in last_message["tool_calls"]: - tool_result = self.execute_tool(tool_call) - tool_results.append({ - "tool": tool_call["function"]["name"], - "result": tool_result - }) - ai_in_progress.extend(tool_results) - else: - # Add messages to history - chat_history.append({ - "role": "user", - "content": [{"type": "text", "text": user_question}] - }) - chat_history.append(last_message) - - # Get next user input - user_question = self.get_next_user_input() - if not user_question: - break - - # Clear ai_in_progress for next turn - ai_in_progress = [] - - turn_count += 1 - - return self.handle_max_turns_reached(chat_history) - - -def test_simple_run(): - """Test that the PromptLayer client is working.""" - try: - # This should work even without specific prompts - print("Testing PromptLayer client initialization...") - pl = PromptLayer(api_key=API_KEY) - print("✓ Client initialized successfully") - return True - except Exception as e: - print(f"✗ Client initialization failed: {e}") - return False - - -def main(): - """Run all tests.""" - print("Testing Multi-Turn Chat Documentation Examples") - print("=" * 50) - - print("\n0. Testing PromptLayer client...") - if not test_simple_run(): - print("\n⚠️ Client initialization failed. Check your API key.") - print("Set PROMPTLAYER_API_KEY environment variable or update the script.") - return - - print("\n1. Testing basic conversation loop...") - try: - result = run_conversation("Hello, how can you help me?") - print("✓ Basic conversation executed successfully") - except Exception as e: - print(f"✗ Basic conversation failed: {e}") - - print("\n2. Testing context retention...") - try: - test_context_retention() - except Exception as e: - print(f"✗ Context retention test failed: {e}") - - print("\n3. Testing message placeholder example...") - try: - test_message_placeholder_example() - except Exception as e: - print(f"✗ Message placeholder test failed: {e}") - - print("\n4. Testing conversation with tools...") - try: - result = run_conversation_with_tools("I need help resetting my password") - print("✓ Conversation with tools executed successfully") - except Exception as e: - print(f"✗ Conversation with tools test failed: {e}") - - print("\n5. Testing tool-enabled assistant class...") - try: - agent = StatelessToolAgent(promptlayer_client) - result = agent.run_conversation("I need help with my account") - print("✓ Tool-enabled assistant class executed successfully") - except Exception as e: - print(f"✗ Tool-enabled assistant class test failed: {e}") - - print("\n" + "=" * 50) - print("Testing complete!") - - -if __name__ == "__main__": - main() \ No newline at end of file diff --git a/testing/test_multi_turn_chat_simple.py b/testing/test_multi_turn_chat_simple.py deleted file mode 100644 index db24f8c..0000000 --- a/testing/test_multi_turn_chat_simple.py +++ /dev/null @@ -1,150 +0,0 @@ -""" -Simple test script for Multi-Turn Chat documentation examples. -This script tests the code examples without infinite loops. -""" - -import os -from typing import Any, Dict, List, Optional -from promptlayer import PromptLayer -from dotenv import load_dotenv - -# Load environment variables from .env file -load_dotenv() - -# Configuration -API_KEY = os.environ.get('PROMPTLAYER_API_KEY') -if not API_KEY: - raise ValueError("PROMPTLAYER_API_KEY not found in environment variables. Please set it in .env file.") - -# Initialize client -promptlayer_client = PromptLayer(api_key=API_KEY) - -print(f"Using API key: {API_KEY[:10]}...") - - -def test_basic_conversation(): - """Test a single exchange without tools.""" - print("\n1. Testing basic conversation...") - try: - result = promptlayer_client.run( - prompt_name="multi-turn-assistant", - input_variables={ - "user_question": "Hello, how are you?", - "chat_history": [], - "ai_in_progress": [] - }, - tags=["test"] - ) - - if result and "prompt_blueprint" in result: - last_message = result["prompt_blueprint"]["prompt_template"]["messages"][-1] - print(f"✓ Response: {last_message.get('content', [{}])[0].get('text', 'No text')[:50]}...") - return True - else: - print("✗ No valid response received") - return False - except Exception as e: - print(f"✗ Error: {e}") - return False - - -def test_conversation_with_history(): - """Test conversation with existing history.""" - print("\n2. Testing conversation with history...") - - chat_history = [ - { - "role": "user", - "content": [{"type": "text", "text": "I'm in New York"}] - }, - { - "role": "assistant", - "content": [{"type": "text", "text": "Great! You're in New York. How can I help you?"}] - } - ] - - try: - result = promptlayer_client.run( - prompt_name="multi-turn-assistant", - input_variables={ - "chat_history": chat_history, - "user_question": "What's the weather like?", - "ai_in_progress": [] - }, - tags=["test"] - ) - - if result and "prompt_blueprint" in result: - last_message = result["prompt_blueprint"]["prompt_template"]["messages"][-1] - response_text = last_message.get('content', [{}])[0].get('text', '') - if 'New York' in response_text or 'weather' in response_text.lower(): - print(f"✓ Context retained: {response_text[:50]}...") - return True - else: - print(f"✓ Response received: {response_text[:50]}...") - return True - else: - print("✗ No valid response received") - return False - except Exception as e: - print(f"✗ Error: {e}") - return False - - -def test_with_tools(): - """Test a single exchange with tools prompt.""" - print("\n3. Testing with tools prompt...") - try: - result = promptlayer_client.run( - prompt_name="multi-turn-assistant-with-tools", - input_variables={ - "chat_history": [], - "user_question": "I need help with my password", - "ai_in_progress": [], - "user_context": {"user_id": "test123"} - }, - tags=["test"] - ) - - if result and "prompt_blueprint" in result: - last_message = result["prompt_blueprint"]["prompt_template"]["messages"][-1] - print(f"✓ Response: {last_message.get('content', [{}])[0].get('text', 'No text')[:50]}...") - return True - else: - print("✗ No valid response received") - return False - except Exception as e: - print(f"✗ Error: {e}") - return False - - -def main(): - """Run all tests.""" - print("=" * 50) - print("Testing Multi-Turn Chat Examples (Simple)") - print("=" * 50) - - results = [] - - # Test basic conversation - results.append(test_basic_conversation()) - - # Test with history - results.append(test_conversation_with_history()) - - # Test with tools - results.append(test_with_tools()) - - print("\n" + "=" * 50) - passed = sum(results) - total = len(results) - print(f"Results: {passed}/{total} tests passed") - - if passed == total: - print("✅ All tests passed!") - else: - print(f"⚠️ {total - passed} test(s) failed") - - -if __name__ == "__main__": - main() \ No newline at end of file diff --git a/testing/test_multi_turn_loop.py b/testing/test_multi_turn_loop.py deleted file mode 100644 index d1fe80a..0000000 --- a/testing/test_multi_turn_loop.py +++ /dev/null @@ -1,213 +0,0 @@ -""" -Test script demonstrating multi-turn conversation with 3+ turns. -""" - -import os -from typing import Any, Dict, List, Optional -from promptlayer import PromptLayer -from dotenv import load_dotenv - -# Load environment variables from .env file -load_dotenv() - -# Configuration -API_KEY = os.environ.get('PROMPTLAYER_API_KEY') -if not API_KEY: - raise ValueError("PROMPTLAYER_API_KEY not found in environment variables.") - -# Initialize client -promptlayer_client = PromptLayer(api_key=API_KEY) - -print(f"Using API key: {API_KEY[:10]}...") - - -def run_multi_turn_conversation(): - """ - Run a multi-turn conversation with at least 3 exchanges. - """ - print("\n" + "="*50) - print("Running Multi-Turn Conversation (3+ turns)") - print("="*50) - - chat_history = [] - - # Define the conversation turns - conversation_turns = [ - "Hello! I'm planning a trip to New York.", - "What's the weather like there in spring?", - "What are some must-see attractions?", - "Thank you for the recommendations!" - ] - - for turn_num, user_question in enumerate(conversation_turns, 1): - print(f"\n--- Turn {turn_num} ---") - print(f"User: {user_question}") - - # Call the prompt with accumulated history - result = promptlayer_client.run( - prompt_name="multi-turn-assistant", - input_variables={ - "user_question": user_question, - "chat_history": chat_history, - "ai_in_progress": [] # Empty for non-tool conversations - }, - tags=["multi-turn-test"] - ) - - # Extract assistant's response - if result and "prompt_blueprint" in result: - last_message = result["prompt_blueprint"]["prompt_template"]["messages"][-1] - assistant_text = last_message.get('content', [{}])[0].get('text', 'No response') - - # Display assistant's response (truncated for readability) - print(f"Assistant: {assistant_text[:150]}{'...' if len(assistant_text) > 150 else ''}") - - # Add both user and assistant messages to history - chat_history.append({ - "role": "user", - "content": [{"type": "text", "text": user_question}] - }) - chat_history.append(last_message) - - # Show history size - print(f"History size: {len(chat_history)} messages") - else: - print("Error: No valid response received") - break - - print("\n" + "="*50) - print(f"Conversation completed with {len(chat_history)//2} exchanges") - print(f"Final history contains {len(chat_history)} messages") - - # Verify context retention - print("\n--- Verifying Context Retention ---") - - # Check if the assistant remembers the trip to New York from turn 1 - final_question = "What city was I asking about again?" - print(f"User: {final_question}") - - result = promptlayer_client.run( - prompt_name="multi-turn-assistant", - input_variables={ - "user_question": final_question, - "chat_history": chat_history, - "ai_in_progress": [] - }, - tags=["context-test"] - ) - - if result and "prompt_blueprint" in result: - last_message = result["prompt_blueprint"]["prompt_template"]["messages"][-1] - assistant_text = last_message.get('content', [{}])[0].get('text', 'No response') - print(f"Assistant: {assistant_text[:200]}") - - # Check if New York is mentioned - if "New York" in assistant_text or "NYC" in assistant_text: - print("✅ Context retained successfully - assistant remembers New York!") - else: - print("⚠️ Context might be lost - New York not mentioned explicitly") - - return True - - -def run_tool_conversation(): - """ - Run a multi-turn conversation with tools. - """ - print("\n" + "="*50) - print("Running Tool-Based Conversation") - print("="*50) - - chat_history = [] - ai_in_progress = [] - - # Simulate a support conversation - questions = [ - "I forgot my password", - "My username is john.doe@example.com", - "Can you send the reset link?" - ] - - for turn_num, user_question in enumerate(questions, 1): - print(f"\n--- Turn {turn_num} ---") - print(f"User: {user_question}") - - result = promptlayer_client.run( - prompt_name="multi-turn-assistant-with-tools", - input_variables={ - "chat_history": chat_history, - "user_question": user_question, - "ai_in_progress": ai_in_progress, - "user_context": { - "user_id": "user_123", - "session_id": "session_456" - } - }, - tags=["tool-test"] - ) - - if result and "prompt_blueprint" in result: - last_message = result["prompt_blueprint"]["prompt_template"]["messages"][-1] - - # Check for tool calls - if last_message.get("tool_calls") or last_message.get("function_call"): - print("Assistant: [Making tool call...]") - # In a real scenario, we'd execute the tool here - # For testing, we just acknowledge it - ai_in_progress.append(last_message) - ai_in_progress.append({ - "role": "tool", - "content": [{"type": "text", "text": "Tool executed successfully"}] - }) - else: - # Regular response - assistant_text = last_message.get('content', [{}])[0].get('text', 'No response') - print(f"Assistant: {assistant_text[:150]}{'...' if len(assistant_text) > 150 else ''}") - - # Add to history - chat_history.append({ - "role": "user", - "content": [{"type": "text", "text": user_question}] - }) - - # Add any tool interactions to history - if ai_in_progress: - chat_history.extend(ai_in_progress) - ai_in_progress = [] - - chat_history.append(last_message) - else: - print("Error: No valid response received") - break - - print(f"\nCompleted {len(questions)} turns") - return True - - -def main(): - """Run all multi-turn tests.""" - print("\n" + "="*60) - print("MULTI-TURN CONVERSATION TEST (3+ TURNS)") - print("="*60) - - try: - # Test basic multi-turn conversation - run_multi_turn_conversation() - - # Test tool-based conversation - try: - run_tool_conversation() - except Exception as e: - print(f"\nTool conversation skipped: {e}") - - print("\n✅ Multi-turn conversation test completed successfully!") - - except Exception as e: - print(f"\n❌ Error during testing: {e}") - return False - - return True - - -if __name__ == "__main__": - main() \ No newline at end of file diff --git a/testing/test_multi_turn_with_tools.py b/testing/test_multi_turn_with_tools.py deleted file mode 100644 index be46e3b..0000000 --- a/testing/test_multi_turn_with_tools.py +++ /dev/null @@ -1,261 +0,0 @@ -""" -Test script demonstrating proper multi-turn conversation with tool calls. -Shows how ai_in_progress accumulates tool interactions between user turns. -""" - -import os -import json -from typing import Any, Dict, List, Optional -from promptlayer import PromptLayer -from dotenv import load_dotenv - -# Load environment variables from .env file -load_dotenv() - -# Configuration -API_KEY = os.environ.get('PROMPTLAYER_API_KEY') -if not API_KEY: - raise ValueError("PROMPTLAYER_API_KEY not found in environment variables.") - -# Initialize client -promptlayer_client = PromptLayer(api_key=API_KEY) - -print(f"Using API key: {API_KEY[:10]}...") - - -def mock_execute_tool(tool_call: Dict[str, Any]) -> str: - """Mock tool execution.""" - tool_name = tool_call.get("function", {}).get("name", "unknown") - - # Mock responses for different tools - if tool_name == "search_kb": - return "Found 3 articles about password reset:\n1. How to reset your password\n2. Password requirements\n3. Troubleshooting login issues" - elif tool_name == "create_ticket": - return "Ticket #12345 created successfully. A support agent will contact you within 24 hours." - elif tool_name == "send_reset_email": - return "Password reset email sent to john.doe@example.com" - else: - return f"Tool {tool_name} failed" - - -def run_tool_conversation_properly(): - """ - Run a multi-turn conversation with proper tool handling. - Shows how ai_in_progress accumulates tool calls and responses. - """ - print("\n" + "="*60) - print("Running Tool-Based Multi-Turn Conversation") - print("="*60) - - chat_history = [] - - # Turn 1: User asks for help - user_question = "I forgot my password and need to reset it" - print(f"\n--- Turn 1 ---") - print(f"User: {user_question}") - - # AI might need to use tools before responding - ai_in_progress = [] - - while True: # Loop to handle multiple tool calls before final response - result = promptlayer_client.run( - prompt_name="multi-turn-assistant-with-tools", - input_variables={ - "chat_history": chat_history, - "user_question": user_question, - "ai_in_progress": ai_in_progress, - "user_context": { - "user_id": "user_123", - "email": "john.doe@example.com" - } - }, - tags=["tool-test"] - ) - - if not result or "prompt_blueprint" not in result: - print("Error: No valid response") - break - - last_message = result["prompt_blueprint"]["prompt_template"]["messages"][-1] - - # Check if AI wants to use a tool - if last_message.get("tool_calls"): - print(f"Assistant is calling tools...") - - # Add AI's message with tool call to ai_in_progress - ai_in_progress.append(last_message) - - # Process each tool call - for tool_call in last_message["tool_calls"]: - tool_name = tool_call.get("function", {}).get("name", "unknown") - print(f" - Calling tool: {tool_name}") - - # Mock execute the tool - tool_result = mock_execute_tool(tool_call) - - # Add tool response to ai_in_progress - tool_response = { - "role": "tool", - "content": [{"type": "text", "text": tool_result}], # Proper format with content array - "tool_call_id": tool_call["id"] - } - ai_in_progress.append(tool_response) - print(f" - Tool response: {tool_result[:50]}...") - print(f"Debug - ai_in_progress now has {len(ai_in_progress)} messages") - - # Continue loop - AI might need to call more tools or provide final response - continue - - else: - # AI provided final response to user - assistant_text = last_message.get('content', [{}])[0].get('text', 'No response') - print(f"Assistant: {assistant_text[:200]}{'...' if len(assistant_text) > 200 else ''}") - - # Add complete exchange to history - chat_history.append({ - "role": "user", - "content": [{"type": "text", "text": user_question}] - }) - - # Add all tool interactions from ai_in_progress - if ai_in_progress: - print(f" (Added {len(ai_in_progress)} tool interaction messages to history)") - print(f" Debug - ai_in_progress contents:") - for i, msg in enumerate(ai_in_progress): - role = msg.get('role', 'unknown') - if role == 'tool': - print(f" [{i}] Tool response: {msg.get('content', [{}])[0].get('text', 'no text')[:50]}...") - else: - print(f" [{i}] AI message with tool calls") - chat_history.extend(ai_in_progress) - - # Add final assistant response - chat_history.append(last_message) - break - - print(f"History after Turn 1: {len(chat_history)} messages") - - # Turn 2: User provides additional information - user_question = "My username is john.doe@example.com" - print(f"\n--- Turn 2 ---") - print(f"User: {user_question}") - - # Clear ai_in_progress for new turn - ai_in_progress = [] - - while True: - result = promptlayer_client.run( - prompt_name="multi-turn-assistant-with-tools", - input_variables={ - "chat_history": chat_history, - "user_question": user_question, - "ai_in_progress": ai_in_progress, - "user_context": { - "user_id": "user_123", - "email": "john.doe@example.com" - } - }, - tags=["tool-test"] - ) - - if not result or "prompt_blueprint" not in result: - break - - last_message = result["prompt_blueprint"]["prompt_template"]["messages"][-1] - - if last_message.get("tool_calls"): - print(f"Assistant is calling tools...") - ai_in_progress.append(last_message) - - for tool_call in last_message["tool_calls"]: - tool_name = tool_call.get("function", {}).get("name", "unknown") - print(f" - Calling tool: {tool_name}") - - tool_result = mock_execute_tool(tool_call) - tool_response = { - "role": "tool", - "content": tool_result, - "tool_call_id": tool_call["id"] - } - ai_in_progress.append(tool_response) - print(f" - Tool response: {tool_result[:50]}...") - - continue - else: - assistant_text = last_message.get('content', [{}])[0].get('text', 'No response') - print(f"Assistant: {assistant_text[:200]}{'...' if len(assistant_text) > 200 else ''}") - - chat_history.append({ - "role": "user", - "content": [{"type": "text", "text": user_question}] - }) - - if ai_in_progress: - print(f" (Added {len(ai_in_progress)} tool interaction messages to history)") - chat_history.extend(ai_in_progress) - - chat_history.append(last_message) - break - - print(f"History after Turn 2: {len(chat_history)} messages") - - # Turn 3: User asks for confirmation - user_question = "Has the reset email been sent?" - print(f"\n--- Turn 3 ---") - print(f"User: {user_question}") - - ai_in_progress = [] - - result = promptlayer_client.run( - prompt_name="multi-turn-assistant-with-tools", - input_variables={ - "chat_history": chat_history, - "user_question": user_question, - "ai_in_progress": ai_in_progress, - "user_context": { - "user_id": "user_123", - "email": "john.doe@example.com" - } - }, - tags=["tool-test"] - ) - - if result and "prompt_blueprint" in result: - last_message = result["prompt_blueprint"]["prompt_template"]["messages"][-1] - assistant_text = last_message.get('content', [{}])[0].get('text', 'No response') - print(f"Assistant: {assistant_text[:200]}{'...' if len(assistant_text) > 200 else ''}") - - # Check if the assistant remembers the context - if "email" in assistant_text.lower() or "sent" in assistant_text.lower() or "john.doe" in assistant_text.lower(): - print("\n✅ Context retained - Assistant remembers the email/action from previous turns!") - else: - print("\n⚠️ Assistant response doesn't explicitly reference previous context") - - print(f"\n" + "="*60) - print(f"Conversation completed with {len(chat_history)} total messages in history") - print("Tool interactions were properly handled via ai_in_progress") - - return True - - -def main(): - """Run the tool conversation test.""" - print("\n" + "="*70) - print("MULTI-TURN CONVERSATION WITH TOOLS TEST") - print("="*70) - - try: - run_tool_conversation_properly() - print("\n✅ Tool conversation test completed successfully!") - - except Exception as e: - print(f"\n❌ Error during testing: {e}") - import traceback - traceback.print_exc() - return False - - return True - - -if __name__ == "__main__": - main() \ No newline at end of file diff --git a/testing/test_tool_debug.py b/testing/test_tool_debug.py deleted file mode 100644 index 8461467..0000000 --- a/testing/test_tool_debug.py +++ /dev/null @@ -1,98 +0,0 @@ -""" -Debug script to understand tool conversation flow. -""" - -import os -import json -from promptlayer import PromptLayer -from dotenv import load_dotenv - -load_dotenv() -client = PromptLayer(api_key=os.environ.get('PROMPTLAYER_API_KEY')) - -print("Testing Tool Conversation Flow") -print("=" * 60) - -chat_history = [] -ai_in_progress = [] -user_question = "I forgot my password and need to reset it" - -print(f"\nUser: {user_question}") -print("\n--- First API Call (no tools yet) ---") - -# First call - should trigger tool call -result = client.run( - prompt_name="multi-turn-assistant-with-tools", - input_variables={ - "chat_history": chat_history, - "user_question": user_question, - "ai_in_progress": ai_in_progress, - "user_context": {"user_id": "test123"} - } -) - -if result: - last_msg = result["prompt_blueprint"]["prompt_template"]["messages"][-1] - - if last_msg.get("tool_calls"): - print(f"AI wants to call {len(last_msg['tool_calls'])} tool(s)") - - # Add AI's message to ai_in_progress - ai_in_progress.append(last_msg) - print(f"Added AI message to ai_in_progress (length: {len(ai_in_progress)})") - - # Add tool responses - for tool_call in last_msg["tool_calls"]: - tool_name = tool_call["function"]["name"] - print(f" Tool: {tool_name}") - - # Create tool response - tool_response = { - "role": "tool", - "content": [{"type": "text", "text": f"Tool {tool_name} executed: Found password reset instructions"}], - "tool_call_id": tool_call["id"] - } - ai_in_progress.append(tool_response) - print(f" Added tool response (ai_in_progress length: {len(ai_in_progress)})") - - print(f"\n--- Second API Call (with tool responses) ---") - print(f"ai_in_progress contains {len(ai_in_progress)} messages:") - for i, msg in enumerate(ai_in_progress): - role = msg.get("role") - if role == "tool": - content = msg.get("content", [{}])[0].get("text", "")[:50] - print(f" [{i}] tool: {content}...") - else: - print(f" [{i}] assistant: (message with tool calls)") - - # Second call with tool responses - print("\nCalling API with tool responses...") - result2 = client.run( - prompt_name="multi-turn-assistant-with-tools", - input_variables={ - "chat_history": chat_history, - "user_question": user_question, - "ai_in_progress": ai_in_progress, - "user_context": {"user_id": "test123"} - } - ) - - if result2: - last_msg2 = result2["prompt_blueprint"]["prompt_template"]["messages"][-1] - - if last_msg2.get("tool_calls"): - print(f"AI wants to call MORE tools: {[tc['function']['name'] for tc in last_msg2['tool_calls']]}") - print("(This might mean the prompt isn't seeing the tool responses)") - else: - print("AI provided final response:") - text = last_msg2.get("content", [{}])[0].get("text", "") - print(f" {text[:200]}...") - else: - print("AI didn't call any tools") - text = last_msg.get("content", [{}])[0].get("text", "") - print(f"Response: {text[:200]}...") - -print("\n" + "=" * 60) -print("Conclusion:") -print("If the AI keeps calling tools, the prompt may not have the ai_in_progress placeholder") -print("or it's not configured to accept tool responses in the expected format.") \ No newline at end of file