Skip to content
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

[FEAT] TaskWeaver Integration #541

Merged
merged 34 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
674d2dc
taskweaver basic tracking
the-praxs Dec 2, 2024
6fe9d31
Merge branch 'main' into feat/taskweaver
the-praxs Dec 3, 2024
c1e99c1
linting
the-praxs Dec 3, 2024
0b7d3a8
Merge branch 'main' into feat/taskweaver
the-praxs Dec 4, 2024
51ae25f
Merge branch 'main' into feat/taskweaver
the-praxs Dec 9, 2024
bdf64aa
Merge branch 'main' into feat/taskweaver
teocns Dec 11, 2024
23eb629
Merge branch 'main' into feat/taskweaver
the-praxs Dec 12, 2024
774eedd
Merge branch 'main' into feat/taskweaver
the-praxs Dec 13, 2024
16c7e9f
Merge branch 'main' into feat/taskweaver
the-praxs Dec 16, 2024
e06e88c
Merge branch 'main' into feat/taskweaver
the-praxs Dec 16, 2024
7e83a07
Merge branch 'main' into feat/taskweaver
the-praxs Dec 17, 2024
1dfeb99
some logging occurs
the-praxs Dec 17, 2024
66c848d
more debug info to understand llm info flow
the-praxs Dec 18, 2024
edea673
saving model info now in `LLMEvent`
the-praxs Dec 18, 2024
caae7f5
get service mappings from taskweaver
the-praxs Dec 18, 2024
aa877fb
remove taskweaver code from agentops init
the-praxs Dec 19, 2024
d794b9f
fix incorrect use of agent_id in events
the-praxs Dec 19, 2024
5523131
clean and refactor code for taskweaver LLM tracking
the-praxs Dec 19, 2024
7f5c2c2
convert `LLMEvent` to `ActionEvent`
the-praxs Dec 19, 2024
e615560
improved event handling
the-praxs Dec 19, 2024
3f5adb8
add `ActionEvent` for recording `json_schema`
the-praxs Dec 19, 2024
1a5a084
linting
the-praxs Dec 19, 2024
b250430
add microsoft and taskweaver logos
the-praxs Dec 20, 2024
1ae51bf
add default tags `taskweaver`
the-praxs Dec 20, 2024
b502582
cast message as string
the-praxs Dec 20, 2024
e278b5c
add session image
the-praxs Dec 20, 2024
c3b0215
add documentation for taskweaver
the-praxs Dec 20, 2024
676e6ca
linting
the-praxs Dec 20, 2024
306a3b5
overhauled handler code
the-praxs Dec 22, 2024
9867928
Merge branch 'main' into feat/taskweaver
the-praxs Dec 22, 2024
f5faec2
linting
the-praxs Dec 22, 2024
d355ce9
use correct logger import
the-praxs Dec 22, 2024
2696ae7
stutter fix
the-praxs Dec 22, 2024
d2724f3
add warning for stutter
the-praxs Dec 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
159 changes: 159 additions & 0 deletions agentops/llms/providers/taskweaver.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
import pprint
from typing import Optional
import json

from agentops.event import ErrorEvent, LLMEvent
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"

Check warning on line 19 in agentops/llms/providers/taskweaver.py

View check run for this annotation

Codecov / codecov/patch

agentops/llms/providers/taskweaver.py#L18-L19

Added lines #L18 - L19 were not covered by tests

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)

Check warning on line 23 in agentops/llms/providers/taskweaver.py

View check run for this annotation

Codecov / codecov/patch

agentops/llms/providers/taskweaver.py#L23

Added line #L23 was not covered by tests

try:
response_dict = response.get("response", {})
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)

Check warning on line 35 in agentops/llms/providers/taskweaver.py

View check run for this annotation

Codecov / codecov/patch

agentops/llms/providers/taskweaver.py#L25-L35

Added lines #L25 - L35 were not covered by tests

except Exception as e:
error_event = ErrorEvent(

Check warning on line 38 in agentops/llms/providers/taskweaver.py

View check run for this annotation

Codecov / codecov/patch

agentops/llms/providers/taskweaver.py#L37-L38

Added lines #L37 - L38 were not covered by tests
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(

Check warning on line 46 in agentops/llms/providers/taskweaver.py

View check run for this annotation

Codecov / codecov/patch

agentops/llms/providers/taskweaver.py#L43-L46

Added lines #L43 - L46 were not covered by tests
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

Check warning on line 52 in agentops/llms/providers/taskweaver.py

View check run for this annotation

Codecov / codecov/patch

agentops/llms/providers/taskweaver.py#L52

Added line #L52 was not covered by tests

def override(self):
"""Override TaskWeaver's chat completion methods"""
global original_chat_completion

try:
from taskweaver.llm.openai import OpenAIService
from taskweaver.llm.anthropic import AnthropicService
from taskweaver.llm.azure_ml import AzureMLService
from taskweaver.llm.groq import GroqService
from taskweaver.llm.ollama import OllamaService
from taskweaver.llm.qwen import QWenService
from taskweaver.llm.zhipuai import ZhipuAIService

Check warning on line 65 in agentops/llms/providers/taskweaver.py

View check run for this annotation

Codecov / codecov/patch

agentops/llms/providers/taskweaver.py#L58-L65

Added lines #L58 - L65 were not covered by tests

# Create our own mapping of services
service_mapping = {

Check warning on line 68 in agentops/llms/providers/taskweaver.py

View check run for this annotation

Codecov / codecov/patch

agentops/llms/providers/taskweaver.py#L68

Added line #L68 was not covered by tests
"openai": OpenAIService,
"azure": OpenAIService,
"azure_ad": OpenAIService,
"anthropic": AnthropicService,
"azure_ml": AzureMLService,
"groq": GroqService,
"ollama": OllamaService,
"qwen": QWenService,
"zhipuai": ZhipuAIService
}

def patched_chat_completion(service, *args, **kwargs):
init_timestamp = get_ISO_time()
session = kwargs.get("session", None)

Check warning on line 82 in agentops/llms/providers/taskweaver.py

View check run for this annotation

Codecov / codecov/patch

agentops/llms/providers/taskweaver.py#L80-L82

Added lines #L80 - L82 were not covered by tests
if "session" in kwargs.keys():
del kwargs["session"]

Check warning on line 84 in agentops/llms/providers/taskweaver.py

View check run for this annotation

Codecov / codecov/patch

agentops/llms/providers/taskweaver.py#L84

Added line #L84 was not covered by tests

result = original_chat_completion(service, *args, **kwargs)
kwargs.update(

Check warning on line 87 in agentops/llms/providers/taskweaver.py

View check run for this annotation

Codecov / codecov/patch

agentops/llms/providers/taskweaver.py#L86-L87

Added lines #L86 - L87 were not covered by tests
{
"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 = ""

Check warning on line 100 in agentops/llms/providers/taskweaver.py

View check run for this annotation

Codecov / codecov/patch

agentops/llms/providers/taskweaver.py#L100

Added line #L100 was not covered by tests
for chunk in result:
if isinstance(chunk, dict) and "content" in chunk:
accumulated_content += chunk["content"]

Check warning on line 103 in agentops/llms/providers/taskweaver.py

View check run for this annotation

Codecov / codecov/patch

agentops/llms/providers/taskweaver.py#L103

Added line #L103 was not covered by tests
else:
accumulated_content += chunk
yield chunk
accumulated_content = json.loads(accumulated_content)
return self.handle_response(accumulated_content, kwargs, init_timestamp, session=session)

Check warning on line 108 in agentops/llms/providers/taskweaver.py

View check run for this annotation

Codecov / codecov/patch

agentops/llms/providers/taskweaver.py#L105-L108

Added lines #L105 - L108 were not covered by tests
else:
return self.handle_response(result, kwargs, init_timestamp, session=session)

Check warning on line 110 in agentops/llms/providers/taskweaver.py

View check run for this annotation

Codecov / codecov/patch

agentops/llms/providers/taskweaver.py#L110

Added line #L110 was not covered by tests

for service_name, service_class in service_mapping.items():
original_chat_completion = service_class.chat_completion
service_class.chat_completion = patched_chat_completion

Check warning on line 114 in agentops/llms/providers/taskweaver.py

View check run for this annotation

Codecov / codecov/patch

agentops/llms/providers/taskweaver.py#L113-L114

Added lines #L113 - L114 were not covered by tests

the-praxs marked this conversation as resolved.
Show resolved Hide resolved
except Exception as e:
logger.error(f"Failed to patch method: {str(e)}", exc_info=True)

Check warning on line 117 in agentops/llms/providers/taskweaver.py

View check run for this annotation

Codecov / codecov/patch

agentops/llms/providers/taskweaver.py#L116-L117

Added lines #L116 - L117 were not covered by tests

def undo_override(self):
"""Restore original TaskWeaver chat completion methods"""
try:
from taskweaver.llm.openai import OpenAIService
from taskweaver.llm.anthropic import AnthropicService
from taskweaver.llm.azure_ml import AzureMLService
from taskweaver.llm.groq import GroqService
from taskweaver.llm.ollama import OllamaService
from taskweaver.llm.qwen import QWenService
from taskweaver.llm.zhipuai import ZhipuAIService

Check warning on line 128 in agentops/llms/providers/taskweaver.py

View check run for this annotation

Codecov / codecov/patch

agentops/llms/providers/taskweaver.py#L121-L128

Added lines #L121 - L128 were not covered by tests

# Create our own mapping of services
service_mapping = {

Check warning on line 131 in agentops/llms/providers/taskweaver.py

View check run for this annotation

Codecov / codecov/patch

agentops/llms/providers/taskweaver.py#L131

Added line #L131 was not covered by tests
"openai": OpenAIService,
"azure": OpenAIService,
"azure_ad": OpenAIService,
"anthropic": AnthropicService,
"azure_ml": AzureMLService,
"groq": GroqService,
"ollama": OllamaService,
"qwen": QWenService,
"zhipuai": ZhipuAIService
}

if original_chat_completion is not None:
for service_name, service_class in service_mapping.items():
service_class.chat_completion = original_chat_completion

Check warning on line 145 in agentops/llms/providers/taskweaver.py

View check run for this annotation

Codecov / codecov/patch

agentops/llms/providers/taskweaver.py#L145

Added line #L145 was not covered by tests

except Exception as e:
logger.error(f"Failed to restore original method: {str(e)}", exc_info=True)

Check warning on line 148 in agentops/llms/providers/taskweaver.py

View check run for this annotation

Codecov / codecov/patch

agentops/llms/providers/taskweaver.py#L147-L148

Added lines #L147 - L148 were not covered by tests

def _get_model_name(self, service) -> str:
"""Extract model name from service instance"""
model_name = "unknown"

Check warning on line 152 in agentops/llms/providers/taskweaver.py

View check run for this annotation

Codecov / codecov/patch

agentops/llms/providers/taskweaver.py#L152

Added line #L152 was not covered by tests
if hasattr(service, "config"):
config = service.config

Check warning on line 154 in agentops/llms/providers/taskweaver.py

View check run for this annotation

Codecov / codecov/patch

agentops/llms/providers/taskweaver.py#L154

Added line #L154 was not covered by tests
if hasattr(config, "model"):
model_name = config.model or "unknown"

Check warning on line 156 in agentops/llms/providers/taskweaver.py

View check run for this annotation

Codecov / codecov/patch

agentops/llms/providers/taskweaver.py#L156

Added line #L156 was not covered by tests
elif hasattr(config, "llm_module_config") and hasattr(config.llm_module_config, "model"):
model_name = config.llm_module_config.model or "unknown"
return model_name

Check warning on line 159 in agentops/llms/providers/taskweaver.py

View check run for this annotation

Codecov / codecov/patch

agentops/llms/providers/taskweaver.py#L158-L159

Added lines #L158 - L159 were not covered by tests
14 changes: 14 additions & 0 deletions agentops/llms/tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from .providers.anthropic import AnthropicProvider
from .providers.mistral import MistralProvider
from .providers.ai21 import AI21Provider
from .providers.taskweaver import TaskWeaverProvider

original_func = {}
original_create = None
Expand Down Expand Up @@ -54,6 +55,9 @@
"client.answer.create",
),
},
"taskweaver": {
"0.0.1": ("chat_completion", "chat_completion_stream"),
},
}

def __init__(self, client):
Expand Down Expand Up @@ -164,6 +168,15 @@
else:
logger.warning(f"Only LlamaStackClient>=0.0.53 supported. v{module_version} found.")

if api == "taskweaver":
module_version = version(api)

Check warning on line 172 in agentops/llms/tracker.py

View check run for this annotation

Codecov / codecov/patch

agentops/llms/tracker.py#L172

Added line #L172 was not covered by tests

if Version(module_version) >= parse("0.0.1"):
provider = TaskWeaverProvider(self.client)
provider.override()

Check warning on line 176 in agentops/llms/tracker.py

View check run for this annotation

Codecov / codecov/patch

agentops/llms/tracker.py#L175-L176

Added lines #L175 - L176 were not covered by tests
else:
logger.warning(f"Only TaskWeaver>=0.0.1 supported. v{module_version} found.")

Check warning on line 178 in agentops/llms/tracker.py

View check run for this annotation

Codecov / codecov/patch

agentops/llms/tracker.py#L178

Added line #L178 was not covered by tests

def stop_instrumenting(self):
OpenAiProvider(self.client).undo_override()
GroqProvider(self.client).undo_override()
Expand All @@ -174,3 +187,4 @@
MistralProvider(self.client).undo_override()
AI21Provider(self.client).undo_override()
LlamaStackClientProvider(self.client).undo_override()
TaskWeaverProvider(self.client).undo_override()

Check warning on line 190 in agentops/llms/tracker.py

View check run for this annotation

Codecov / codecov/patch

agentops/llms/tracker.py#L190

Added line #L190 was not covered by tests
160 changes: 160 additions & 0 deletions agentops/partners/taskweaver_event_handler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
from taskweaver.module.event_emitter import (

Check warning on line 1 in agentops/partners/taskweaver_event_handler.py

View check run for this annotation

Codecov / codecov/patch

agentops/partners/taskweaver_event_handler.py#L1

Added line #L1 was not covered by tests
SessionEventHandlerBase,
TaskWeaverEvent,
EventScope,
SessionEventType,
RoundEventType,
PostEventType,
)
import agentops
from typing import Dict, Optional, Any
from uuid import UUID

Check warning on line 11 in agentops/partners/taskweaver_event_handler.py

View check run for this annotation

Codecov / codecov/patch

agentops/partners/taskweaver_event_handler.py#L9-L11

Added lines #L9 - L11 were not covered by tests


class TaskWeaverEventHandler(SessionEventHandlerBase):
def __init__(self):
super().__init__()
self.current_round_id: Optional[str] = None
self.agent_sessions: Dict[str, Any] = {}
self._message_buffer: Dict[str, str] = {}
self._attachment_buffer: Dict[str, Dict[str, Any]] = {}
self._active_agents: Dict[str, str] = {} # Maps role_round_id to agent_id

Check warning on line 21 in agentops/partners/taskweaver_event_handler.py

View check run for this annotation

Codecov / codecov/patch

agentops/partners/taskweaver_event_handler.py#L14-L21

Added lines #L14 - L21 were not covered by tests

def _get_or_create_agent(self, role: str) -> str:

Check warning on line 23 in agentops/partners/taskweaver_event_handler.py

View check run for this annotation

Codecov / codecov/patch

agentops/partners/taskweaver_event_handler.py#L23

Added line #L23 was not covered by tests
"""Get existing agent ID or create new agent for role+round combination"""
agent_key = f"{role}"

Check warning on line 25 in agentops/partners/taskweaver_event_handler.py

View check run for this annotation

Codecov / codecov/patch

agentops/partners/taskweaver_event_handler.py#L25

Added line #L25 was not covered by tests
if agent_key not in self._active_agents:
agent_id = agentops.create_agent(name=role)

Check warning on line 27 in agentops/partners/taskweaver_event_handler.py

View check run for this annotation

Codecov / codecov/patch

agentops/partners/taskweaver_event_handler.py#L27

Added line #L27 was not covered by tests
if agent_id: # Only store if agent creation was successful
self._active_agents[agent_key] = agent_id
return self._active_agents.get(agent_key)

Check warning on line 30 in agentops/partners/taskweaver_event_handler.py

View check run for this annotation

Codecov / codecov/patch

agentops/partners/taskweaver_event_handler.py#L29-L30

Added lines #L29 - L30 were not covered by tests

def handle_session(self, type: SessionEventType, msg: str, extra: Any, **kwargs: Any):
agentops.record(

Check warning on line 33 in agentops/partners/taskweaver_event_handler.py

View check run for this annotation

Codecov / codecov/patch

agentops/partners/taskweaver_event_handler.py#L32-L33

Added lines #L32 - L33 were not covered by tests
agentops.ActionEvent(action_type=type.value, params={"message": msg}, returns=str(extra) if extra else None)
)

def handle_round(self, type: RoundEventType, msg: str, extra: Any, round_id: str, **kwargs: Any):

Check warning on line 37 in agentops/partners/taskweaver_event_handler.py

View check run for this annotation

Codecov / codecov/patch

agentops/partners/taskweaver_event_handler.py#L37

Added line #L37 was not covered by tests
if type == RoundEventType.round_start:
self.current_round_id = round_id
agentops.record(agentops.ActionEvent(action_type="round_start", params={"round_id": round_id}, returns=msg))

Check warning on line 40 in agentops/partners/taskweaver_event_handler.py

View check run for this annotation

Codecov / codecov/patch

agentops/partners/taskweaver_event_handler.py#L39-L40

Added lines #L39 - L40 were not covered by tests

elif type == RoundEventType.round_error:
agentops.record(agentops.ErrorEvent(error_type="round_error", details=msg, logs={"round_id": round_id}))

Check warning on line 43 in agentops/partners/taskweaver_event_handler.py

View check run for this annotation

Codecov / codecov/patch

agentops/partners/taskweaver_event_handler.py#L43

Added line #L43 was not covered by tests

elif type == RoundEventType.round_end:
agentops.record(agentops.ActionEvent(action_type="round_end", params={"round_id": round_id}, returns=msg))
self.current_round_id = None

Check warning on line 47 in agentops/partners/taskweaver_event_handler.py

View check run for this annotation

Codecov / codecov/patch

agentops/partners/taskweaver_event_handler.py#L46-L47

Added lines #L46 - L47 were not covered by tests

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)

Check warning on line 51 in agentops/partners/taskweaver_event_handler.py

View check run for this annotation

Codecov / codecov/patch

agentops/partners/taskweaver_event_handler.py#L49-L51

Added lines #L49 - L51 were not covered by tests

if type == PostEventType.post_start:
agentops.record(

Check warning on line 54 in agentops/partners/taskweaver_event_handler.py

View check run for this annotation

Codecov / codecov/patch

agentops/partners/taskweaver_event_handler.py#L54

Added line #L54 was not covered by tests
agentops.ActionEvent(
action_type="post_start",
params={
"post_id": post_id,
"round_id": round_id,
"agent_id": agent_id,
},
returns=msg,
)
)

elif type == PostEventType.post_message_update:
is_end = extra.get("is_end", False)

Check warning on line 67 in agentops/partners/taskweaver_event_handler.py

View check run for this annotation

Codecov / codecov/patch

agentops/partners/taskweaver_event_handler.py#L67

Added line #L67 was not covered by tests
if not is_end:
self._message_buffer[post_id] = self._message_buffer.get(post_id, "") + msg

Check warning on line 69 in agentops/partners/taskweaver_event_handler.py

View check run for this annotation

Codecov / codecov/patch

agentops/partners/taskweaver_event_handler.py#L69

Added line #L69 was not covered by tests
else:
agentops.record(

Check warning on line 71 in agentops/partners/taskweaver_event_handler.py

View check run for this annotation

Codecov / codecov/patch

agentops/partners/taskweaver_event_handler.py#L71

Added line #L71 was not covered by tests
agentops.ActionEvent(
action_type="post_message_update",
params={
"post_id": post_id,
"round_id": round_id,
"agent_id": agent_id,
"is_end": is_end,
"model": extra.get("model", None),
"prompt": self._message_buffer.get(post_id, ""),
},
returns=extra.get("message", "")
)
)

if is_end:
self._message_buffer.pop(post_id, None)

Check warning on line 87 in agentops/partners/taskweaver_event_handler.py

View check run for this annotation

Codecov / codecov/patch

agentops/partners/taskweaver_event_handler.py#L87

Added line #L87 was not covered by tests

elif type == PostEventType.post_attachment_update:
attachment_id = extra.get("id", "")
attachment_type = extra.get("type", "")
is_end = extra.get("is_end", False)

Check warning on line 92 in agentops/partners/taskweaver_event_handler.py

View check run for this annotation

Codecov / codecov/patch

agentops/partners/taskweaver_event_handler.py#L90-L92

Added lines #L90 - L92 were not covered by tests

if attachment_id not in self._attachment_buffer:
self._attachment_buffer[attachment_id] = {

Check warning on line 95 in agentops/partners/taskweaver_event_handler.py

View check run for this annotation

Codecov / codecov/patch

agentops/partners/taskweaver_event_handler.py#L95

Added line #L95 was not covered by tests
"type": attachment_type,
"content": "",
"post_id": post_id,
"round_id": round_id,
"agent_id": agent_id,
}

agentops.record(

Check warning on line 103 in agentops/partners/taskweaver_event_handler.py

View check run for this annotation

Codecov / codecov/patch

agentops/partners/taskweaver_event_handler.py#L103

Added line #L103 was not covered by tests
agentops.ActionEvent(
action_type="attachment_stream_start",
params={
"attachment_id": attachment_id,
"attachment_type": str(attachment_type),
"post_id": post_id,
"round_id": round_id,
"agent_id": agent_id,
},
)
)

self._attachment_buffer[attachment_id]["content"] += msg

Check warning on line 116 in agentops/partners/taskweaver_event_handler.py

View check run for this annotation

Codecov / codecov/patch

agentops/partners/taskweaver_event_handler.py#L116

Added line #L116 was not covered by tests

if is_end:
buffer = self._attachment_buffer[attachment_id]
agentops.record(

Check warning on line 120 in agentops/partners/taskweaver_event_handler.py

View check run for this annotation

Codecov / codecov/patch

agentops/partners/taskweaver_event_handler.py#L119-L120

Added lines #L119 - L120 were not covered by tests
agentops.ToolEvent(
name=str(buffer["type"]),
params={
"post_id": buffer["post_id"],
"round_id": buffer["round_id"],
"attachment_id": attachment_id,
},
returns=buffer["content"],
agent_id=buffer["agent_id"],
)
)
self._attachment_buffer.pop(attachment_id)

Check warning on line 132 in agentops/partners/taskweaver_event_handler.py

View check run for this annotation

Codecov / codecov/patch

agentops/partners/taskweaver_event_handler.py#L132

Added line #L132 was not covered by tests

elif type == PostEventType.post_error:
agentops.record(

Check warning on line 135 in agentops/partners/taskweaver_event_handler.py

View check run for this annotation

Codecov / codecov/patch

agentops/partners/taskweaver_event_handler.py#L135

Added line #L135 was not covered by tests
agentops.ErrorEvent(
error_type="post_error",
details=msg,
logs={"post_id": post_id, "round_id": round_id},
)
)

elif type == PostEventType.post_end:
agentops.record(

Check warning on line 144 in agentops/partners/taskweaver_event_handler.py

View check run for this annotation

Codecov / codecov/patch

agentops/partners/taskweaver_event_handler.py#L144

Added line #L144 was not covered by tests
agentops.ActionEvent(
action_type="post_end",
params={
"post_id": post_id,
"round_id": round_id,
"agent_id": agent_id
},
returns=msg,
)
)

def cleanup_round(self, round_id: str):

Check warning on line 156 in agentops/partners/taskweaver_event_handler.py

View check run for this annotation

Codecov / codecov/patch

agentops/partners/taskweaver_event_handler.py#L156

Added line #L156 was not covered by tests
"""Cleanup agents and buffers for a completed round"""
self._active_agents = {k: v for k, v in self._active_agents.items() if not k.endswith(round_id)}
self._message_buffer.clear()
self._attachment_buffer.clear()

Check warning on line 160 in agentops/partners/taskweaver_event_handler.py

View check run for this annotation

Codecov / codecov/patch

agentops/partners/taskweaver_event_handler.py#L158-L160

Added lines #L158 - L160 were not covered by tests
Loading