Spaces:
Running
Running
Commit ·
edf083b
1
Parent(s): 7e807a3
add
Browse filesFiles changed (5)
19 unmodified lines2021222319 unmodified linesdescription: str = Field(..., description="One-sentence explanation of the failure")raw_text: str = Field("", description="Exact snippet of trace text that evidences the failure (can be left blank and recovered via raw_text_ref)")raw_text_ref: List[ContentReference] = Field(..., description="List of references to every occurrence of the failure evidence in the trace")affected_id: Optional[str] = Field(None, description="ID of related Entity or Relation responsible for or impacted by the failure")19 unmodified lines2021222319 unmodified linesdescription: str = Field(..., description="One-sentence explanation of the failure")raw_text: str = Field("", description="Exact snippet of trace text that evidences the failure (can be left blank and recovered via raw_text_ref)")raw_text_ref: List[ContentReference] = Field(..., description="List of references to every occurrence of the failure evidence in the trace")affected_id: str = Field(..., description="ID of related Entity or Relation responsible for or impacted by the failure")
18 unmodified lines1920212218 unmodified linesrecommendation_type: RecommendationType = Field(..., description="The category of optimization being suggested")description: str = Field(..., description="A detailed, human-readable explanation of the recommendation, including the observed pattern and the justification for the change.")affected_ids: List[str] = Field(default_factory=list, description="A list of Entity or Relation IDs that are the focus of this recommendation")raw_text_ref: Optional[List[ContentReference]] = Field(default=None, description="Optional list of references to the exact trace locations related to this recommendation")18 unmodified lines1920212218 unmodified linesrecommendation_type: RecommendationType = Field(..., description="The category of optimization being suggested")description: str = Field(..., description="A detailed, human-readable explanation of the recommendation, including the observed pattern and the justification for the change.")affected_ids: List[str] = Field(default_factory=list, description="A list of Entity or Relation IDs that are the focus of this recommendation")raw_text_ref: List[ContentReference] = Field(default_factory=list, description="List of references to the exact trace locations related to this recommendation")
11 unmodified lines121314151611 unmodified linessystem_summary: str = Field("", description="A short 2-3 sentence summary of the agent system's purpose and structure")entities: List[Entity] = Field(default_factory=list, description="List of entities in the knowledge graph")relations: List[Relation] = Field(default_factory=list, description="List of relations in the knowledge graph")failures: Optional[List['Failure']] = Field(default=None, description="Optional list of detected risk or failure events across the trace")optimizations: Optional[List[OptimizationRecommendation]] = Field(default=None, description="Optional list of recommendations for optimizing the agent system")11 unmodified lines121314151611 unmodified linessystem_summary: str = Field("", description="A short 2-3 sentence summary of the agent system's purpose and structure")entities: List[Entity] = Field(default_factory=list, description="List of entities in the knowledge graph")relations: List[Relation] = Field(default_factory=list, description="List of relations in the knowledge graph")failures: List[Failure] = Field(default_factory=list, description="List of detected risk or failure events across the trace")optimizations: List[OptimizationRecommendation] = Field(default_factory=list, description="List of recommendations for optimizing the agent system")
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172#!/usr/bin/env python3"""Simple test to verify OpenAI structured outputs functionality"""
import osfrom dotenv import load_dotenvfrom openai import OpenAIfrom pydantic import BaseModelfrom typing import List
# Load environment variablesload_dotenv('/Users/zekunwu/Desktop/agent_monitoring/.env')
class SimpleEntity(BaseModel): name: str type: str
class SimpleKG(BaseModel): entities: List[SimpleEntity] system_name: str
def test_basic_openai(): """Test basic OpenAI structured outputs""" # Check if API key exists api_key = os.getenv("OPENAI_API_KEY") if not api_key: print("❌ OPENAI_API_KEY not found in environment") return False if api_key == "your_openai_api_key_here": print("❌ Please set a real OpenAI API key in .env file") return False print(f"✅ API key found: {api_key[:10]}...") try: client = OpenAI(api_key=api_key) response = client.responses.parse( model="gpt-4o-2024-08-06", input=[ {"role": "system", "content": "Extract entities from text."}, {"role": "user", "content": "Alice the manager uses Excel tool to analyze data."} ], text_format=SimpleKG, ) result = response.output_parsed print(f"✅ OpenAI API call successful!") print(f"System: {result.system_name}") print(f"Entities: {len(result.entities)}") for entity in result.entities: print(f" - {entity.type}: {entity.name}") return True except Exception as e: print(f"❌ OpenAI API call failed: {e}") return False
if __name__ == "__main__": print("🧪 Testing Basic OpenAI Structured Outputs") print("=" * 50) success = test_basic_openai() if success: print("\n🎉 Basic test passed! Ready to use OpenAI structured outputs.") else: print("\n💥 Basic test failed. Please check your OpenAI API key.")123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110#!/usr/bin/env python3"""Test with simplified KnowledgeGraph model"""
import osimport sysfrom dotenv import load_dotenvfrom openai import OpenAIfrom pydantic import BaseModel, Fieldfrom typing import List, Optional
# Load environment variablesload_dotenv('/Users/zekunwu/Desktop/agent_monitoring/.env')
# Simplified modelsclass SimpleEntity(BaseModel): id: str type: str # Agent, Task, Tool, Input, Output, Human name: str importance: str # HIGH, MEDIUM, LOW
class SimpleRelation(BaseModel): id: str source: str target: str type: str # PERFORMS, USES, etc. importance: str
class SimpleKnowledgeGraph(BaseModel): system_name: str = Field("", description="Name of the system") system_summary: str = Field("", description="Summary of the system") entities: List[SimpleEntity] = Field(default_factory=list) relations: List[SimpleRelation] = Field(default_factory=list)
def test_simple_kg(): """Test with simplified KG model""" client = OpenAI(api_key=os.getenv("OPENAI_API_KEY")) test_input = """ Assistant: I'll help you analyze the customer data to find purchasing patterns.
Action: load_data Action Input: {"dataset": "customer_purchases.csv"} Observation: Data loaded successfully. Found 10,000 customer records.
Action: analyze_patterns Action Input: {"columns": ["purchase_amount", "product_category", "customer_age"]} Observation: Analysis complete. Found strong correlation between age and product preferences.
Final Answer: Based on the analysis, customers aged 25-35 prefer electronics. """ system_prompt = """Extract a knowledge graph with these entity types:- Agent: AI agents - Task: Specific tasks- Tool: Tools or functions- Input: Data inputs- Output: Data outputs- Human: Human users
Use these relationship types:- PERFORMS: Agent→Task- USES: Agent→Tool- PRODUCES: Task→Output
Create entities with IDs like agent_001, task_001, etc."""
try: print("🧪 Testing Simplified Knowledge Graph Extraction") print("=" * 60) response = client.responses.parse( model="gpt-4o-2024-08-06", input=[ {"role": "system", "content": system_prompt}, {"role": "user", "content": f"Extract knowledge graph from: {test_input}"} ], text_format=SimpleKnowledgeGraph, ) kg = response.output_parsed print(f"✅ Extraction successful!") print(f"📊 System: {kg.system_name}") print(f"📝 Summary: {kg.system_summary}") print(f"🔢 Entities: {len(kg.entities)}") print(f"🔗 Relations: {len(kg.relations)}") print("\n📋 Entities:") for entity in kg.entities: print(f" - {entity.id}: {entity.type} - {entity.name} ({entity.importance})") print("\n🔗 Relations:") for relation in kg.relations: print(f" - {relation.id}: {relation.source} → {relation.target} ({relation.type})") return True except Exception as e: print(f"❌ Test failed: {e}") return False
if __name__ == "__main__": success = test_simple_kg() if success: print("\n🎉 Simplified KG test passed!") else: print("\n💥 Simplified KG test failed.")agentgraph/shared/models/reference_based/failure.py+1-1
agentgraph/shared/models/reference_based/optimization_recommendation.py+1-1
agentgraph/shared/models/reference_based/report.py+2-2
simple_test.pyDeleted-72
test_simple_kg.pyDeleted-110