Python SDK for AI agent monitoring, LLM cost tracking, benchmarking, and more. Integrates with most LLMs and agent frameworks including CrewAI, Agno, OpenAI Agents SDK, Langchain, Autogen, AG2, and CamelAI
Python agentagentopsagents-sdkaianthropicautogencost-estimationcrewaievalsevaluation-metricsgroqlangchainllmmistralollamaopenaiopenai-agents
[FEAT] TaskWeaver Integration (#541)
Pratyush Shukla5d4ff2f713e8
diff --git a/agentops/llms/providers/taskweaver.py b/agentops/llms/providers/taskweaver.pynew file mode 100644index 00000000..2254897f--- /dev/null+++ b/agentops/llms/providers/taskweaver.py@@ -0,0 +1,146 @@+import pprint+from typing import Optional+import json++from agentops.event import ErrorEvent, LLMEvent, ActionEvent+from agentops.session import Session+from agentops.log_config import logger+from agentops.helpers import get_ISO_time, check_call_stack_for_agent_id+from agentops.llms.providers.instrumented_provider import InstrumentedProvider+from agentops.singleton import singleton+++@singleton+class TaskWeaverProvider(InstrumentedProvider):+ original_chat_completion = None++ def __init__(self, client):+ super().__init__(client)+ self._provider_name = "TaskWeaver"+ self.client.add_default_tags(["taskweaver"])++ def handle_response(self, response, kwargs, init_timestamp, session: Optional[Session] = None) -> dict:+ """Handle responses for TaskWeaver"""+ llm_event = LLMEvent(init_timestamp=init_timestamp, params=kwargs)+ action_event = ActionEvent(init_timestamp=init_timestamp)++ try:+ response_dict = response.get("response", {})++ action_event.params = kwargs.get("json_schema", None)+ action_event.returns = response_dict+ action_event.end_timestamp = get_ISO_time()+ self._safe_record(session, action_event)+ except Exception as e:+ error_event = ErrorEvent(+ trigger_event=action_event, exception=e, details={"response": str(response), "kwargs": str(kwargs)}+ )+ self._safe_record(session, error_event)+ kwargs_str = pprint.pformat(kwargs)+ response_str = pprint.pformat(response)+ logger.error(+ f"Unable to parse response for Action call. Skipping upload to AgentOps\n"+ f"response:\n {response_str}\n"+ f"kwargs:\n {kwargs_str}\n"+ )++ try:+ llm_event.init_timestamp = init_timestamp+ llm_event.params = kwargs+ llm_event.returns = response_dict+ llm_event.agent_id = check_call_stack_for_agent_id()+ llm_event.model = kwargs.get("model", "unknown")+ llm_event.prompt = kwargs.get("messages")+ llm_event.completion = response_dict.get("message", "")+ llm_event.end_timestamp = get_ISO_time()+ self._safe_record(session, llm_event)++ except Exception as e:+ error_event = ErrorEvent(+ trigger_event=llm_event, exception=e, details={"response": str(response), "kwargs": str(kwargs)}+ )+ self._safe_record(session, error_event)+ kwargs_str = pprint.pformat(kwargs)+ response_str = pprint.pformat(response)+ logger.error(+ f"Unable to parse response for LLM call. Skipping upload to AgentOps\n"+ f"response:\n {response_str}\n"+ f"kwargs:\n {kwargs_str}\n"+ )++ return response++ def override(self):+ """Override TaskWeaver's chat completion methods"""+ try:+ from taskweaver.llm import llm_completion_config_map++ def create_patched_chat_completion(original_method):+ """Create a new patched chat_completion function with bound original method"""++ def patched_chat_completion(service, *args, **kwargs):+ init_timestamp = get_ISO_time()+ session = kwargs.get("session", None)+ if "session" in kwargs.keys():+ del kwargs["session"]++ result = original_method(service, *args, **kwargs)+ kwargs.update(+ {+ "model": self._get_model_name(service),+ "messages": args[0],+ "stream": args[1],+ "temperature": args[2],+ "max_tokens": args[3],+ "top_p": args[4],+ "stop": args[5],+ }+ )++ if kwargs["stream"]:+ accumulated_content = ""+ for chunk in result:+ if isinstance(chunk, dict) and "content" in chunk:+ accumulated_content += chunk["content"]+ else:+ accumulated_content += chunk+ yield chunk+ accumulated_content = json.loads(accumulated_content)+ return self.handle_response(accumulated_content, kwargs, init_timestamp, session=session)+ else:+ return self.handle_response(result, kwargs, init_timestamp, session=session)++ return patched_chat_completion++ for service_name, service_class in llm_completion_config_map.items():+ if not hasattr(service_class, "_original_chat_completion"):+ service_class._original_chat_completion = service_class.chat_completion+ service_class.chat_completion = create_patched_chat_completion(+ service_class._original_chat_completion+ )++ except Exception as e:+ logger.error(f"Failed to patch method: {str(e)}", exc_info=True)++ def undo_override(self):+ """Restore original TaskWeaver chat completion methods"""+ try:+ from taskweaver.llm import llm_completion_config_map++ for service_name, service_class in llm_completion_config_map.items():+ service_class.chat_completion = service_class._original_chat_completion+ delattr(service_class, "_original_chat_completion")++ except Exception as e:+ logger.error(f"Failed to restore original method: {str(e)}", exc_info=True)++ def _get_model_name(self, service) -> str:+ """Extract model name from service instance"""+ model_name = "unknown"+ if hasattr(service, "config"):+ config = service.config+ if hasattr(config, "model"):+ model_name = config.model or "unknown"+ elif hasattr(config, "llm_module_config") and hasattr(config.llm_module_config, "model"):+ model_name = config.llm_module_config.model or "unknown"+ return model_namediff --git a/agentops/llms/tracker.py b/agentops/llms/tracker.pyindex 06ed7de8..928cfa26 100644--- a/agentops/llms/tracker.py+++ b/agentops/llms/tracker.py@@ -16,6 +16,7 @@ from .providers.openai import OpenAiProviderfrom .providers.anthropic import AnthropicProviderfrom .providers.mistral import MistralProviderfrom .providers.ai21 import AI21Provider+from .providers.taskweaver import TaskWeaverProvideroriginal_func = {}original_create = None@@ -54,6 +55,9 @@ class LlmTracker:"client.answer.create",),},+ "taskweaver": {+ "0.0.1": ("chat_completion", "chat_completion_stream"),+ },}def __init__(self, client):@@ -164,6 +168,15 @@ class LlmTracker:else:logger.warning(f"Only LlamaStackClient>=0.0.53 supported. v{module_version} found.")+ if api == "taskweaver":+ module_version = version(api)++ if Version(module_version) >= parse("0.0.1"):+ provider = TaskWeaverProvider(self.client)+ provider.override()+ else:+ logger.warning(f"Only TaskWeaver>=0.0.1 supported. v{module_version} found.")+def stop_instrumenting(self):OpenAiProvider(self.client).undo_override()GroqProvider(self.client).undo_override()@@ -174,3 +187,4 @@ class LlmTracker:MistralProvider(self.client).undo_override()AI21Provider(self.client).undo_override()LlamaStackClientProvider(self.client).undo_override()+ TaskWeaverProvider(self.client).undo_override()diff --git a/agentops/partners/taskweaver_event_handler.py b/agentops/partners/taskweaver_event_handler.pynew file mode 100755index 00000000..18a179d7--- /dev/null+++ b/agentops/partners/taskweaver_event_handler.py@@ -0,0 +1,191 @@+from taskweaver.module.event_emitter import (+ SessionEventHandlerBase,+ SessionEventType,+ RoundEventType,+ PostEventType,+)+import agentops+from agentops.event import ActionEvent, ErrorEvent, ToolEvent+from datetime import datetime, timezone+from typing import Dict, Any+from agentops.log_config import logger++ATTACHMENT_TOOLS = [+ "thought",+ "reply_type",+ "reply_content",+ "verification",+ "code_error",+ "execution_status",+ "execution_result",+ "artifact_paths",+ "revise_message",+ "function",+ "web_exploring_plan",+ "web_exploring_screenshot",+ "web_exploring_link",+]+++class TaskWeaverEventHandler(SessionEventHandlerBase):+ def __init__(self):+ super().__init__()+ self._message_buffer: Dict[str, Dict[str, Any]] = {}+ self._attachment_buffer: Dict[str, Dict[str, Any]] = {}+ self._active_agents: Dict[str, str] = {}++ def _get_or_create_agent(self, role: str):+ """Get existing agent ID or create new agent for role+round combination"""+ if role not in self._active_agents:+ agent_id = agentops.create_agent(name=role)+ if agent_id:+ self._active_agents[role] = agent_id+ return self._active_agents.get(role)++ def handle_session(self, type: SessionEventType, msg: str, extra: Any, **kwargs: Any):+ agentops.record(ActionEvent(action_type=type.value, params={"extra": extra, "message": msg}))++ def handle_round(self, type: RoundEventType, msg: str, extra: Any, round_id: str, **kwargs: Any):+ if type == RoundEventType.round_error:+ agentops.record(+ ErrorEvent(error_type=type.value, details={"round_id": round_id, "message": msg, "extra": extra})+ )+ logger.error(f"Could not record the Round event: {msg}")+ self.cleanup_round()+ else:+ agentops.record(+ ActionEvent(+ action_type=type.value,+ params={"round_id": round_id, "extra": extra},+ returns=msg,+ )+ )+ if type == RoundEventType.round_end:+ self.cleanup_round()++ def handle_post(self, type: PostEventType, msg: str, extra: Any, post_id: str, round_id: str, **kwargs: Any):+ role = extra.get("role", "Planner")+ agent_id = self._get_or_create_agent(role=role)++ if type == PostEventType.post_error:+ agentops.record(+ ErrorEvent(+ error_type=type.value,+ details={"post_id": post_id, "round_id": round_id, "message": msg, "extra": extra},+ )+ )+ logger.error(f"Could not record the Post event: {msg}")++ elif type == PostEventType.post_start or type == PostEventType.post_end:+ agentops.record(+ ActionEvent(+ action_type=type.value,+ params={"post_id": post_id, "round_id": round_id, "extra": extra},+ returns=msg,+ agent_id=agent_id,+ )+ )++ elif type == PostEventType.post_status_update:+ agentops.record(+ ActionEvent(+ action_type=type.value,+ params={"post_id": post_id, "round_id": round_id, "extra": extra},+ returns=msg,+ agent_id=agent_id,+ )+ )++ elif type == PostEventType.post_attachment_update:+ attachment_id = extra["id"]+ attachment_type = extra["type"].value+ is_end = extra["is_end"]++ if attachment_id not in self._attachment_buffer:+ self._attachment_buffer[attachment_id] = {+ "role": attachment_type,+ "content": [],+ "init_timestamp": datetime.now(timezone.utc).isoformat(),+ "end_timestamp": None,+ }++ self._attachment_buffer[attachment_id]["content"].append(str(msg))++ if is_end:+ self._attachment_buffer[attachment_id]["end_timestamp"] = datetime.now(timezone.utc).isoformat()+ complete_message = "".join(self._attachment_buffer[attachment_id]["content"])++ if attachment_type in ATTACHMENT_TOOLS:+ agentops.record(+ ToolEvent(+ name=type.value,+ init_timestamp=self._attachment_buffer[attachment_id]["init_timestamp"],+ end_timestamp=self._attachment_buffer[attachment_id]["end_timestamp"],+ params={+ "post_id": post_id,+ "round_id": round_id,+ "attachment_id": attachment_id,+ "attachment_type": self._attachment_buffer[attachment_id]["role"],+ "extra": extra,+ },+ returns=complete_message,+ agent_id=agent_id,+ )+ )+ else:+ agentops.record(+ ActionEvent(+ action_type=type.value,+ init_timestamp=self._attachment_buffer[attachment_id]["init_timestamp"],+ end_timestamp=self._attachment_buffer[attachment_id]["end_timestamp"],+ params={+ "post_id": post_id,+ "round_id": round_id,+ "attachment_id": attachment_id,+ "attachment_type": self._attachment_buffer[attachment_id]["role"],+ "extra": extra,+ },+ returns=complete_message,+ agent_id=agent_id,+ )+ )++ self._attachment_buffer.pop(attachment_id, None)++ elif type == PostEventType.post_message_update:+ is_end = extra["is_end"]++ if post_id not in self._message_buffer:+ self._message_buffer[post_id] = {+ "content": [],+ "init_timestamp": datetime.now(timezone.utc).isoformat(),+ "end_timestamp": None,+ }++ self._message_buffer[post_id]["content"].append(str(msg))++ if is_end:+ self._message_buffer[post_id]["end_timestamp"] = datetime.now(timezone.utc).isoformat()+ complete_message = "".join(self._message_buffer[post_id]["content"])+ agentops.record(+ ActionEvent(+ action_type=type.value,+ init_timestamp=self._message_buffer[post_id]["init_timestamp"],+ end_timestamp=self._message_buffer[post_id]["end_timestamp"],+ params={+ "post_id": post_id,+ "round_id": round_id,+ "extra": extra,+ },+ returns=complete_message,+ agent_id=agent_id,+ )+ )++ self._message_buffer.pop(post_id, None)++ def cleanup_round(self):+ """Cleanup agents and buffers for a completed round"""+ self._active_agents.clear()+ self._message_buffer.clear()+ self._attachment_buffer.clear()diff --git a/docs/images/external/microsoft/microsoft_logo.svg b/docs/images/external/microsoft/microsoft_logo.svgnew file mode 100644index 00000000..5334aa7c--- /dev/null+++ b/docs/images/external/microsoft/microsoft_logo.svg@@ -0,0 +1 @@+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 23 23"><path fill="#f3f3f3" d="M0 0h23v23H0z"/><path fill="#f35325" d="M1 1h10v10H1z"/><path fill="#81bc06" d="M12 1h10v10H12z"/><path fill="#05a6f0" d="M1 12h10v10H1z"/><path fill="#ffba08" d="M12 12h10v10H12z"/></svg>\ No newline at end of filediff --git a/docs/images/external/microsoft/taskweaver_logo.svg b/docs/images/external/microsoft/taskweaver_logo.svgnew file mode 100644index 00000000..0ce6d88f--- /dev/null+++ b/docs/images/external/microsoft/taskweaver_logo.svg@@ -0,0 +1,11 @@+<?xml version="1.0" encoding="utf-8"?>+<svg viewBox="50 45 710 710" xmlns="http://www.w3.org/2000/svg">+ <path+ d="M 591.149 243.424 C 586.76 240.797 580.173 238.872 573.739 238.872 C 567.306 238.872 560.777 240.76 556.386 243.389 C 551.906 246.336 547.892 251.744 547.892 256.776 C 547.892 260.166 549.483 268.369 556.685 270.818 C 537.111 268.954 510.909 289.148 501.419 302.944 C 500.601 297.132 506.473 281.166 517.438 276.692 C 508.083 277.561 493.729 288.387 491.707 294.047 C 482.563 291.29 463.903 290.969 454.572 290.9 C 463.675 278.711 477.983 260.767 494.392 248.593 C 484.869 263.71 477.992 277.819 480.364 283.235 C 481.301 276.259 488.802 260.235 500.777 244.148 C 507.031 240.078 513.734 236.544 520.866 233.857 C 507.929 249.977 496.613 267.747 499.558 275.086 C 500.706 266.777 511.713 246.938 528.728 231.299 C 532.597 230.239 536.581 229.438 540.676 228.939 C 526.041 242.928 511.632 260.718 514.913 269.648 C 516.209 260.563 530.082 239.667 550.984 228.346 C 554.278 228.367 557.638 228.588 561.062 229.03 C 545.378 239.34 528.406 254.848 531.938 265.373 C 533.369 255.714 550.121 235.616 574.736 231.916 C 587.23 235.568 600.483 242.208 614.446 252.675 C 614.446 252.675 597.239 265.979 596.504 265.689 C 599.019 262.841 599.586 260.13 599.586 256.776 C 599.586 251.744 595.631 246.373 591.149 243.424 Z"+ style="fill: rgb(136, 153, 102);" />+ <path+ d="M 594.586 256.776 C 594.586 263.903 585.253 269.68 573.739 269.68 C 562.226 269.68 552.892 263.903 552.892 256.776 C 552.892 249.649 562.226 243.872 573.739 243.872 C 585.253 243.872 594.586 249.649 594.586 256.776 Z"+ style="fill: rgb(51, 68, 85);" />+ <path style="fill: rgb(0, 68, 85);"+ d="M 107.131 272.222 C 171.168 345.864 259.898 361.047 301.235 354.57 C 294.044 362.388 286.908 371.054 279.864 380.641 C 234.114 376.584 94.779 351.774 107.131 272.222 Z M 118.029 196.561 C 143.964 257.222 275.499 317.946 328.361 329.112 C 321.603 334.514 314.855 340.568 308.145 347.333 C 263.113 335.67 86.724 277.108 118.029 196.561 Z M 150.847 116.344 C 167.106 196.966 306.817 294.104 356.447 310.258 C 348.823 314.453 341.163 319.381 333.508 325.125 C 280.818 302.794 92.674 214.626 150.847 116.344 Z M 190.955 47.066 C 212.057 126.175 340.131 260.75 392.182 295.504 C 383.305 298.015 374.283 301.383 365.186 305.755 C 321.587 279.533 119.002 149.972 190.955 47.066 Z M 259.982 410.659 C 187.419 410.659 157.913 390.88 131.725 356.015 C 185.995 380.638 236.092 395.657 274.107 388.713 C 269.348 395.585 264.636 402.892 259.982 410.659 Z M 555.994 410.19 C 528.351 528.661 422.403 532.236 391.744 530.712 C 382.353 523.215 373.247 515.873 364.492 508.757 C 414.747 509.979 517.438 492.762 537.303 410.19 C 574.384 256.053 672.467 233.468 672.467 233.468 C 647.406 233.81 626.783 248.797 626.783 248.797 C 524.87 171.369 453.389 269.902 442.168 290.381 L 416.36 292.367 C 503.052 145.453 620.025 224.204 620.025 224.204 C 664.364 214.939 711.849 226.351 711.849 226.351 C 711.849 226.351 588.421 271.217 555.994 410.19 Z M 186.21 410.659 C 186.21 410.659 229.845 425.381 248.546 423.458 C 248.546 423.458 606.954 739.979 733.521 751.153 C 685.534 755.937 578.928 751.794 559.604 729.991 C 576.435 699.209 188.081 413.224 186.21 410.659 Z M 66.478 678.239 C 66.478 678.239 151.553 673.951 229.665 564.466 C 231.154 569.672 233.652 575.369 236.995 581.231 C 221.818 595.835 203.922 625.118 204.133 630.869 C 204.133 630.869 227.724 600.769 244.413 594.545 C 247.315 598.238 251.032 601.619 254.445 605.149 C 230.448 625.984 229.759 640.604 229.759 640.604 C 229.759 640.604 241.659 617.225 262.061 612.999 C 265.029 615.642 270.287 619.521 273.498 621.899 C 259.656 631.799 248.605 643.538 237.051 655.134 C 211.094 681.184 189.036 734.748 189.036 734.748 C 189.036 734.748 195.607 681.141 206.003 666.68 C 185.701 673.191 139.448 733.904 139.448 733.904 C 139.448 733.904 156.526 682.025 174.674 669.311 C 162.796 676.179 110.489 703.062 102.231 723.639 C 102.231 723.639 115.012 691.391 146.696 671.947 C 96.476 692.106 66.478 678.239 66.478 678.239 Z M 547.252 724.752 C 547.252 724.752 533.604 717.569 512.837 707.95 C 508.882 697.868 505.053 687.698 501.424 677.659 C 529.493 702.199 547.864 720.185 547.252 724.752 Z M 407.441 667.782 C 289.789 635.646 213.969 592.392 232.18 488.002 C 259.388 562.216 321.42 639.413 356.846 638.973 C 338.174 631.037 258.872 525.081 244.881 470.793 C 246.838 472.31 249.154 474.108 251.795 476.16 C 291.814 554.146 373.707 649.398 407.805 652.52 C 407.921 657.804 408.083 662.98 408.288 668.014 C 408.005 667.936 407.723 667.859 407.441 667.782 Z M 407.653 623.525 C 389.05 612.31 360.153 577.567 335.395 541.729 C 358.548 560.058 383.672 580.104 408.257 600.008 C 407.939 607.887 407.743 615.756 407.653 623.525 Z M 407.622 626.677 C 407.562 634.357 407.605 641.928 407.74 649.304 C 371.423 631.605 309.329 550.372 280.334 498.409 C 288.104 504.485 296.681 511.209 305.855 518.422 C 341.115 571.77 385.301 619.317 407.622 626.677 Z M 423.945 612.751 C 430.436 618.043 436.851 623.296 443.139 628.475 C 446.199 647.455 449.826 666.033 453.605 682.969 C 443.422 679.139 432.978 675.483 422.589 672.231 C 422.4 651.864 422.878 631.471 423.945 612.751 Z M 459.614 642.114 C 466.951 648.223 474.038 654.175 480.789 659.905 C 486.031 674.119 491.444 687.886 496.747 700.67 C 487.756 696.699 477.973 692.543 467.751 688.459 C 464.643 672.864 461.89 657.139 459.614 642.114 Z M 353.608 499.326 C 337.26 502.49 464.469 479.28 490.837 439.201 C 517.205 399.122 551.227 279.161 595.778 269.396 C 556.883 298.792 534.856 403.785 508.195 444.957 C 478.468 490.864 353.608 499.326 353.608 499.326 Z M 399.147 476.75 C 399.147 476.75 437.917 457.595 465.712 422.825 C 493.508 388.055 529.749 282.613 574.647 274.142 C 534.705 299.644 509.551 396.692 480.139 431.06 C 440.709 477.137 399.147 476.75 399.147 476.75 Z M 454.411 420.295 C 459.076 389.422 493.478 297.081 547.753 279.794 C 512.363 300.362 485.375 380.283 454.411 420.295 Z M 448.911 345.911 C 448.911 345.911 463.611 343.715 471.474 345.61 C 462.495 361.759 444.106 421.869 431.38 440.054 C 410.723 469.573 367.292 480.784 342.907 491.791 L 327.238 479.102 C 365.247 468.37 388.792 455.822 408.742 438.761 C 441.087 411.101 447.789 370.738 448.911 345.911 Z M 435.539 346.294 C 435.163 360.304 434.239 398.56 412.448 422.476 C 388.822 448.407 345.655 463.94 317.366 470.549 L 303.425 459.899 C 336.509 451.388 364.295 444.313 384.237 429.207 C 413.498 407.043 421.806 370.258 414.201 349.685 C 414.201 349.685 425.017 345.359 435.539 346.294 Z M 496.543 310.404 C 459.83 298.96 387.114 301.28 345.121 338.589 C 380.363 324.922 445.863 311.332 488.202 321.087 C 490.213 317.128 496.543 310.404 496.543 310.404 Z M 482.688 328.805 C 466.155 323.338 366.55 316.666 299.04 379.117 C 299.04 379.117 395.128 325.158 475.657 338.967 C 475.657 338.967 479.09 332.207 482.688 328.805 Z M 403.43 351.209 C 403.43 360.875 406.776 393.153 387.889 410.659 C 367.861 429.222 325.123 446.299 296.834 452.908 L 283.471 442.258 C 356.634 432.887 394.266 390.547 380.763 360.027 C 386.66 356.63 400.23 351.535 403.43 351.209 Z M 363.521 365.081 C 370.209 376.882 367.93 396.707 350.315 410.659 C 331.636 425.453 304.349 432.025 277.965 437.292 L 263.516 424.466 C 339.758 411.171 345.098 397.149 363.521 365.081 Z M 342.823 370.436 C 344.76 377.737 318.999 410.659 275.534 410.659 C 279.112 404.036 286.616 395.374 291.684 389.036 C 315.554 385.802 324.521 382.279 342.823 370.436 Z M 412.766 546.279 C 412.766 546.279 429.23 560.071 439.362 568.039 C 483.177 554.118 541.391 512.913 545.744 467.942 C 512.786 527.472 426.598 549.146 412.766 546.279 Z M 455.802 580.611 C 455.802 580.611 475.876 599.36 484.816 601.404 C 535.776 564.786 614.448 480.447 577.659 370.263 C 574.3 377.611 566.484 402.922 563.152 416.945 C 581.665 518.67 455.802 580.611 455.802 580.611 Z" />+</svg>\ No newline at end of filediff --git a/docs/images/external/microsoft/taskweaver_session.png b/docs/images/external/microsoft/taskweaver_session.pngnew file mode 100644index 00000000..e4feca95Binary files /dev/null and b/docs/images/external/microsoft/taskweaver_session.png differdiff --git a/docs/mint.json b/docs/mint.jsonindex 6751cf79..e53011f1 100644--- a/docs/mint.json+++ b/docs/mint.json@@ -102,6 +102,7 @@"v1/integrations/ollama","v1/integrations/openai","v1/integrations/rest",+ "v1/integrations/taskweaver","v1/integrations/xai"]},diff --git a/docs/v1/examples/examples.mdx b/docs/v1/examples/examples.mdxindex ed3c554d..7dbea88f 100644--- a/docs/v1/examples/examples.mdx+++ b/docs/v1/examples/examples.mdx@@ -85,6 +85,10 @@ mode: "wide"Create a REST server that performs and observes agent tasks</Card>+ <Card title="TaskWeaver" icon={<img src="https://www.github.com/agentops-ai/agentops/blob/main/docs/images/external/microsoft/microsoft_logo.svg?raw=true" alt="TaskWeaver" />} iconType="image" href="/v1/integrations/taskweaver">+ First class support for Microsoft TaskWeaver+ </Card>+<Card title="xAI" icon={<img src="https://www.github.com/agentops-ai/agentops/blob/main/docs/images/external/xai/xai-logo.png?raw=true" alt="xAI" />} iconType="image" href="/v1/integrations/xai">Observe the power of Grok and Grok Vision with AgentOps</Card>diff --git a/docs/v1/integrations/taskweaver.mdx b/docs/v1/integrations/taskweaver.mdxnew file mode 100644index 00000000..97901e0e--- /dev/null+++ b/docs/v1/integrations/taskweaver.mdx@@ -0,0 +1,104 @@+---+title: TaskWeaver+description: "First class support for Microsoft TaskWeaver"+---++import CodeTooltip from '/snippets/add-code-tooltip.mdx'+import EnvTooltip from '/snippets/add-env-tooltip.mdx'++[TaskWeaver](https://microsoft.github.io/TaskWeaver/) is a code-first agent framework for seamlessly planning and executing data analytics tasks. Explore TaskWeaver's comprehensive [documentation](https://microsoft.github.io/TaskWeaver/docs/overview) for more information.++## Steps to integrate TaskWeaver with AgentOps++<Steps>+ <Step title="Install the AgentOps SDK">+ <CodeGroup>+ ```bash pip+ pip install agentops+ ```+ ```bash poetry+ poetry add agentops+ ```+ </CodeGroup>+ </Step>+ <Step title="Install TaskWeaver and configure your project directory">+ Follow the instructions on the TaskWeaver [Quick Start](https://microsoft.github.io/TaskWeaver/docs/quickstart) section in the documentation.+ </Step>+ <Step title="Import the TaskWeaver handler from AgentOps and initialize the AgentOps client">+ AgentOps uses the TaskWeaver handler to handle its events. Additionally, AgentOps tracks the LLM calls made by TaskWeaver via its inbuilt module. These are used together to observe everything in the TaskWeaver session.+ <Note>+ TaskWeaver provides different [usage options](https://microsoft.github.io/TaskWeaver/docs/usage). By default, it's used as a CLI app via the `taskweaver` command but can also be used as a library.+ </Note>+ <CodeGroup>+ ```python python+ import agentops+ from agentops.partners.taskweaver_event_handler import TaskWeaverEventHandler+ from taskweaver.app.app import TaskWeaverApp++ agentops.init(<INSERT YOUR API KEY HERE>)++ # Your TaskWeaver code here++ agentops.end_session("Success")+ ```+ </CodeGroup>+ <EnvTooltip />+ <CodeGroup>+ ```python .env+ AGENTOPS_API_KEY=<YOUR API KEY>+ ```+ </CodeGroup>+ Read more about environment variables in [Advanced Configuration](/v1/usage/advanced-configuration)+ </Step>+ <Step title="Run your Agent">+ Execute your program and visit [app.agentops.ai/drilldown](https://app.agentops.ai/drilldown) to observe your TaskWeaver Agent! 🕵️+ <Tip>+ After your run, AgentOps prints a clickable url to console linking directly to your session in the Dashboard+ </Tip>+ <div/>+ <Frame type="glass" caption="Clickable link to session">+ <img height="200" src="https://github.com/AgentOps-AI/agentops/blob/main/docs/images/external/microsoft/taskweaver_session.png?raw=true" />+ </Frame>+ </Step>+</Steps>++## Full Examples++This is a basic example of how to use TaskWeaver as a library and observe it with AgentOps.++Ensure you have configured your project directory in the TaskWeaverApp by following the documentation mentioned in step 2.++<Warning>+ When registering the TaskWeaverEventHandler, you should either use the `session.event_emitter.register` method or pass the handler object to the `event_handler` parameter in the `send_message` method. If you use both, the events will be recorded twice, resulting in a "stuttering" effect in the recorded messages.+</Warning>++<CodeGroup>+```python python+import agentops++from taskweaver.app.app import TaskWeaverApp+from agentops.partners.taskweaver_event_handler import TaskWeaverEventHandler++agentops.init(<INSERT YOUR API KEY HERE>)++app_dir = "<path to your configured project directory>"+app = TaskWeaverApp(app_dir=app_dir)+session = app.get_session()+handler = TaskWeaverEventHandler()+session.event_emitter.register(handler)++user_query = "Hello, what are the capabilities of TaskWeaver?"+response_round = session.send_message(user_query)++user_query = "Write me a simple calculator program in python"+response_round = session.send_message(user_query)++agentops.end_session("Success")+```+</CodeGroup>++<script type="module" src="/scripts/github_stars.js"></script>+<script type="module" src="/scripts/scroll-img-fadein-animation.js"></script>+<script type="module" src="/scripts/button_heartbeat_animation.js"></script>+<script type="css" src="/styles/styles.css"></script>+<script type="module" src="/scripts/adjust_api_dynamically.js"></script>