diff --git a/README.md b/README.md index 16bb165..1cec817 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,4 @@ To integrate the Proxy with your AI agent, you’ll need to modify how your clie Coming Soon! ### Run -docker compose -f docker-compose.local.yml down -&& docker compose -f docker-compose.local.yml up -d --build -&& docker logs explorer-proxy-explorer-proxy-1 -f \ No newline at end of file +./run.sh up \ No newline at end of file diff --git a/proxy/routes/anthropic.py b/proxy/routes/anthropic.py index f209663..86706f9 100644 --- a/proxy/routes/anthropic.py +++ b/proxy/routes/anthropic.py @@ -89,18 +89,14 @@ async def push_to_explorer( """Pushes the full trace to the Invariant Explorer""" # Combine the messages from the request body and Anthropic response messages = request_body.get("messages", []) - if merged_response is not list: - merged_response = [merged_response] - messages += merged_response + messages += [merged_response] - # Only push the trace to explorer if the last message is an end turn message - if messages[-1].get("stop_reason") in END_REASONS: - messages = anthropic_to_invariant_messages(messages) - _ = await push_trace( - dataset_name=dataset_name, - messages=[messages], - invariant_authorization=invariant_authorization, - ) + messages = anthropic_to_invariant_messages(messages) + _ = await push_trace( + dataset_name=dataset_name, + messages=[messages], + invariant_authorization=invariant_authorization, + ) async def handle_non_streaming_response( response: httpx.Response, @@ -110,12 +106,14 @@ async def handle_non_streaming_response( ): """Handles non-streaming Anthropic responses""" json_response = response.json() - await push_to_explorer( - dataset_name, - json_response, - request_body_json, - invariant_authorization, - ) + # Only push the trace to explorer if the last message is an end turn message + if json_response.get("stop_reason") in END_REASONS: + await push_to_explorer( + dataset_name, + json_response, + request_body_json, + invariant_authorization, + ) def anthropic_to_invariant_messages( messages: list[dict], keep_empty_tool_response: bool = False diff --git a/tests/anthropic/test_claude_weather_agent.py b/tests/anthropic/test_claude_weather_agent.py index 299001c..bb61c3c 100644 --- a/tests/anthropic/test_claude_weather_agent.py +++ b/tests/anthropic/test_claude_weather_agent.py @@ -7,10 +7,11 @@ from httpx import Client import os # from invariant import testing tavily_client = TavilyClient(api_key=os.getenv("TAVILY_API_KEY")) +import datetime class WeatherAgent: def __init__(self, api_key: str): - dataset_name = "claude_weather_agent_test7" + dataset_name = "claude_weather_agent_test" + str(datetime.datetime.now().strftime("%Y%m%d%H%M%S")) invariant_api_key = os.environ.get("INVARIANT_API_KEY") self.client = anthropic.Anthropic( http_client=Client(