-
Notifications
You must be signed in to change notification settings - Fork 15
Fix miscellaneous type hints #45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
229b195
717e45f
cec0c1d
e0c8efd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -67,13 +67,15 @@ def __init__( | |
| self.project_id = project_id | ||
| self.default_tags = default_tags or [] | ||
| self.auto_start_session = auto_start_session | ||
| self.enable_tracing = kwargs.get("enable_tracing", True) | ||
| self.client: Any = None | ||
| self.platform = MonitoringPlatform.AGENTOPS | ||
| """ | ||
| Initialize LangSmith adapter. | ||
|
|
||
| Args: | ||
| api_key: LangSmith API key | ||
| project_name: Project name for organizing traces | ||
| project_id: Langsmith project ID | ||
| endpoint: Optional custom LangSmith endpoint | ||
| enable_tracing: Whether to enable automatic tracing | ||
| enable_feedback: Whether to collect feedback data | ||
|
|
@@ -98,9 +100,10 @@ def _initialize_agentops(self): | |
| """Initialize AgentOps client and verify connection.""" | ||
| try: | ||
| # Import AgentOps SDK | ||
| import agentops | ||
| import agentops # type: ignore[import-not-found] | ||
|
|
||
| self.agentops = agentops | ||
| self.client = agentops | ||
|
|
||
| # Initialize AgentOps | ||
| if self.api_key: | ||
|
|
@@ -124,11 +127,6 @@ def _initialize_agentops(self): | |
| logger.error(f"Failed to connect to AgentOps: {e}") | ||
| raise | ||
|
|
||
| @property | ||
| def platform(self) -> MonitoringPlatform: | ||
| """Return the monitoring platform type.""" | ||
| return MonitoringPlatform.AGENTOPS | ||
|
|
||
| def create_agent(self, role: AgentRole, agent_id: str | None = None, **kwargs) -> AgentMetadata: | ||
| """ | ||
| Create an agent for AgentOps monitoring. | ||
|
|
@@ -244,7 +242,7 @@ def send_message( | |
| interaction = AgentInteraction( | ||
| interaction_id=interaction_id, | ||
| from_agent=from_agent, | ||
| to_agent=to_agent, | ||
| to_agent=to_agent or "broadcast", | ||
| content=message, | ||
| timestamp=timestamp, | ||
| metadata=metadata or {}, | ||
|
|
@@ -339,12 +337,15 @@ def calculate_coordination_metrics(self) -> dict[str, float]: | |
| for interaction in self.session_interactions: | ||
| unique_agents.add(interaction.from_agent) | ||
| if interaction.to_agent: | ||
| unique_agents.add(interaction.to_agent) | ||
| if isinstance(interaction.to_agent, list): | ||
| unique_agents.update(interaction.to_agent) | ||
| else: | ||
| unique_agents.add(interaction.to_agent) | ||
|
|
||
| agent_participation = len(unique_agents) | ||
|
|
||
| # Calculate message distribution | ||
| agent_counts = {} | ||
| agent_counts: dict[str, int] = {} | ||
| for interaction in self.session_interactions: | ||
| from_agent = interaction.from_agent | ||
| agent_counts[from_agent] = agent_counts.get(from_agent, 0) + 1 | ||
|
|
@@ -374,7 +375,7 @@ def calculate_coordination_metrics(self) -> dict[str, float]: | |
| else 0.0, | ||
| } | ||
|
|
||
| def run_scenario(self, scenario: Scenario) -> ScenarioResult: | ||
| async def run_scenario(self, scenario: Scenario) -> ScenarioResult: | ||
| """ | ||
| Run a scenario with LangSmith integration. | ||
|
|
||
|
|
@@ -390,14 +391,14 @@ def run_scenario(self, scenario: Scenario) -> ScenarioResult: | |
| scenario_run_id = None | ||
| if self.enable_tracing: | ||
| try: | ||
| run = self.client.create_run( | ||
| run_id = self.agentops.start_trace( | ||
| name=f"Scenario: {scenario.name}", | ||
| run_type="chain", | ||
| project_name=self.project_name, | ||
| inputs={"scenario": scenario.name, "description": scenario.description}, | ||
| project_name=self.project_id, | ||
| inputs={"scenario": scenario.name}, | ||
| tags=["agentunit", "scenario"], | ||
| ) | ||
| scenario_run_id = str(run.id) | ||
| scenario_run_id = str(run_id) | ||
|
Comment on lines
+394
to
+401
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🌐 Web query:
💡 Result: Here are the AgentOps Python SDK docs and the key details for start_trace, update_trace_metadata, and end_trace.
Concise examples (from docs):
Docs pages:
Would you like direct links to any of those pages or a full code snippet tailored to your app? 🏁 Script executed: cd /tmp && find . -name "agentops_adapter.py" -type f 2>/dev/null | head -1Repository: aviralgarg05/agentunit Length of output: 48 🏁 Script executed: # Search for the file in the repository
git ls-files | grep agentops_adapter.pyRepository: aviralgarg05/agentunit Length of output: 108 🏁 Script executed: # Check imports and initialization in the adapter file
head -50 src/agentunit/adapters/agentops_adapter.pyRepository: aviralgarg05/agentunit Length of output: 1388 🏁 Script executed: # Search for other start_trace calls in the codebase
rg "start_trace" --type pyRepository: aviralgarg05/agentunit Length of output: 160 🏁 Script executed: # Check the full __init__ method and how self.agentops is initialized
sed -n '40,150p' src/agentunit/adapters/agentops_adapter.pyRepository: aviralgarg05/agentunit Length of output: 3978 🏁 Script executed: # Look for agentops import and initialization
rg "import.*agentops|from.*agentops|self\.agentops\s*=" src/agentunit/adapters/agentops_adapter.py -A 3Repository: aviralgarg05/agentunit Length of output: 235 🏁 Script executed: # Check around line 394-401 for more context
sed -n '380,410p' src/agentunit/adapters/agentops_adapter.pyRepository: aviralgarg05/agentunit Length of output: 1221 🏁 Script executed: # Check if there's a custom wrapper around agentops being used
rg "class.*AgentOps|def start_trace|def update_trace_metadata|def end_trace" src/agentunit/adapters/agentops_adapter.py -B 2 -A 5Repository: aviralgarg05/agentunit Length of output: 316 🏁 Script executed: # Check the entire run_scenario method to see how start_trace, update_trace_metadata, end_trace are used
sed -n '370,550p' src/agentunit/adapters/agentops_adapter.pyRepository: aviralgarg05/agentunit Length of output: 6746 All three AgentOps trace method calls use incorrect parameter signatures incompatible with the official SDK. Lines 394-401 call Lines 487-491 and 527-531 call
Additionally, the method docstring incorrectly states "Run a scenario with LangSmith integration" (line ~382) despite being in the AgentOpsAdapter class. Refactor all three method calls to match the official AgentOps SDK signatures, and correct the docstring. 🤖 Prompt for AI Agents |
||
| except Exception as e: | ||
| logger.warning(f"Failed to create scenario run: {e}") | ||
|
|
||
|
|
@@ -483,15 +484,11 @@ def run_scenario(self, scenario: Scenario) -> ScenarioResult: | |
| # Update LangSmith run with results | ||
| if scenario_run_id and self.enable_tracing: | ||
| try: | ||
| self.client.update_run( | ||
| run_id=scenario_run_id, | ||
| outputs={ | ||
| "result": result.passed, | ||
| "execution_time": execution_time, | ||
| "details": result.details, | ||
| }, | ||
| end_time=datetime.now(timezone.utc), | ||
| self.agentops.update_trace_metadata( | ||
| trace_id=scenario_run_id, | ||
| metadata={"result": result.success_rate, "details": result.to_dict()}, | ||
| ) | ||
| self.agentops.end_trace(trace_id=scenario_run_id, status_code="SUCCESS") | ||
| except Exception as e: | ||
| logger.warning(f"Failed to update scenario run: {e}") | ||
|
|
||
|
|
@@ -527,11 +524,11 @@ def run_scenario(self, scenario: Scenario) -> ScenarioResult: | |
| # Update LangSmith run with error | ||
| if scenario_run_id and self.enable_tracing: | ||
| try: | ||
| self.client.update_run( | ||
| run_id=scenario_run_id, | ||
| outputs={"error": str(e)}, | ||
| end_time=datetime.now(timezone.utc), | ||
| self.agentops.update_trace_metadata( | ||
| trace_id=scenario_run_id, | ||
| metadata={"result": result.success_rate, "details": result.to_dict()}, | ||
| ) | ||
| self.agentops.end_trace(trace_id=scenario_run_id, status_code="SUCCESS") | ||
| except Exception as e: | ||
| logger.warning(f"Failed to update failed scenario run: {e}") | ||
|
|
||
|
|
@@ -551,7 +548,7 @@ def collect_metrics(self, scenario: Any, result: Any, **kwargs) -> ProductionMet | |
| """ | ||
| try: | ||
| # Query recent runs from LangSmith | ||
| runs = list(self.client.list_runs(project_name=self.project_name, limit=100)) | ||
| runs = list(self.client.list_runs(project_name=self.project_id, limit=100)) | ||
|
|
||
| if not runs: | ||
| return ProductionMetrics( | ||
|
|
@@ -637,7 +634,7 @@ def establish_baseline( | |
| # Query historical runs | ||
| runs = list( | ||
| self.client.list_runs( | ||
| project_name=self.project_name, start_time=start_date, end_time=end_date | ||
| project_name=self.project_id, start_time=start_date, end_time=end_date | ||
| ) | ||
| ) | ||
|
|
||
|
|
@@ -749,7 +746,7 @@ def create_evaluation_dataset( | |
| logger.error(f"Failed to create LangSmith dataset: {e}") | ||
| raise | ||
|
|
||
| def run_evaluation(self, dataset_id: str, evaluator_function: Any, **kwargs) -> dict[str, Any]: | ||
| def run_evaluation(self, dataset_id: str, evaluator_function: Any, **kwargs) -> Any: | ||
| """ | ||
| Run evaluation on a LangSmith dataset. | ||
|
|
||
|
|
@@ -767,7 +764,7 @@ def run_evaluation(self, dataset_id: str, evaluator_function: Any, **kwargs) -> | |
| results = evaluate( | ||
| evaluator_function, | ||
| data=dataset_id, | ||
| project_name=f"{self.project_name}-evaluation", | ||
| experiment_prefix=f"{self.project_id}-evaluation", | ||
| **kwargs, | ||
| ) | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: aviralgarg05/agentunit
Length of output: 4591
🌐 Web query:
AgentOps Python SDK client API list_runs method💡 Result:
Do you mean the AgentOps SDK's method signature / example usage for a client.list_runs (to list runs/traces), or are you seeing an error when calling list_runs? Which language (pure agentops Python SDK, or the Public API via HTTP) and which version do you have?
🌐 Web query:
AgentOps Python SDK init method returns client session💡 Result:
Yes — agentops.init() creates the SDK client and (by default) starts a session and returns a Session object. If you call agentops.init(auto_start_session=False) it will initialize the client without starting/returning a session. The docs also note the init call constructs the underlying Client (accessible via get_client()). [1][2]
Sources:
🌐 Web query:
AgentOps SDK API methods list_runs create_dataset create_example💡 Result:
I couldn't find public AgentOps SDK methods named exactly list_runs, create_dataset, or create_example in the AgentOps docs or SDK source. The official docs show the Python/TS SDK surface and a REST API (you can fetch the OpenAPI spec for full endpoint names), and AgentOps exposes session/run-related endpoints via its REST API. See:
If you want, I can:
Which would you prefer?
Sources:
[1] https://docs.agentops.ai/v2/usage/sdk-reference
[2] https://docs.agentops.ai/v1/integrations/rest
🏁 Script executed:
Repository: aviralgarg05/agentunit
Length of output: 1232
Critical issue:
self.clientis assigned to theagentopsmodule but code calls non-existent LangSmith API methods.At lines 103–106, the code assigns the
agentopsmodule to bothself.agentopsandself.client. However,agentops.init()(lines 110, 116) returns aSessionobject that is never captured. More critically, lines 551, 636, 728, and 735 attempt to callself.client.list_runs(),self.client.create_dataset(), andself.client.create_example()— methods that do not exist in the AgentOps SDK. These are LangSmith API methods (as evidenced by the comment "Query recent runs from LangSmith" at line 550). The adapter appears to be an incompletely adapted copy of the LangSmith adapter and will fail at runtime withAttributeErrorwhen these methods are invoked. Either capture theSessionobject returned byagentops.init()and use AgentOps-compatible APIs, or remove functionality that relies on non-existent methods.🤖 Prompt for AI Agents