Skip to content

Commit

Permalink
Merge branch 'main' into timetravel-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
HowieG committed Aug 15, 2024
2 parents a411e45 + 9a50c75 commit 4c53ec6
Show file tree
Hide file tree
Showing 20 changed files with 888 additions and 1,167 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/test-notebooks.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
name: Test Notebooks
on:
pull_request_target: # Allows manual triggering from PR UI
push:
branches: [ main ]
pull_request:
branches: [ main ]
branches:
- main
paths-ignore:
- 'docs/**'
jobs:
test-notebooks:
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ To use the handler, import and set
import os
from langchain.chat_models import ChatOpenAI
from langchain.agents import initialize_agent, AgentType
from agentops.langchain_callback_handler import LangchainCallbackHandler
from agentops.partners.langchain_callback_handler import LangchainCallbackHandler

AGENTOPS_API_KEY = os.environ['AGENTOPS_API_KEY']
handler = LangchainCallbackHandler(api_key=AGENTOPS_API_KEY, tags=['Langchain Example'])
Expand Down
4 changes: 0 additions & 4 deletions agentops/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,3 @@ def main():
set_time_travel_active_state(True)
if args.off:
set_time_travel_active_state(False)


if __name__ == "__main__":
main()
5 changes: 4 additions & 1 deletion agentops/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ def configure(
)

def initialize(self) -> Union[Session, None]:
if self.is_initialized:
return

self.unsuppress_logs()

if self._config.api_key is None:
Expand Down Expand Up @@ -348,7 +351,7 @@ def handle_exception(exc_type, exc_value, exc_traceback):
atexit.register(
lambda: cleanup(
end_state="Indeterminate",
end_state_reason="Process exited without calling end_session()",
end_state_reason="N/A (process exited without calling agentops.end_session(...))",
)
)
signal.signal(signal.SIGINT, signal_handler)
Expand Down
50 changes: 33 additions & 17 deletions agentops/partners/langchain_callback_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,8 @@ def __init__(
endpoint: Optional[str] = None,
max_wait_time: Optional[int] = None,
max_queue_size: Optional[int] = None,
tags: Optional[List[str]] = None,
default_tags: Optional[List[str]] = None,
):

logging_level = os.getenv("AGENTOPS_LOGGING_LEVEL")
log_levels = {
"CRITICAL": logging.CRITICAL,
Expand All @@ -64,12 +63,19 @@ def __init__(
"endpoint": endpoint,
"max_wait_time": max_wait_time,
"max_queue_size": max_queue_size,
"tags": tags,
"default_tags": default_tags,
}

self.ao_client = AOClient(
**{k: v for k, v in client_params.items() if v is not None}, override=False
)
self.ao_client = AOClient()
if self.ao_client.session_count == 0:
self.ao_client.configure(
**{k: v for k, v in client_params.items() if v is not None},
instrument_llm_calls=False,
)

if not self.ao_client.is_initialized:
self.ao_client.initialize()

self.agent_actions: Dict[UUID, List[ActionEvent]] = defaultdict(list)
self.events = Events()

Expand All @@ -93,7 +99,6 @@ def on_llm_start(
}, # TODO: params is inconsistent, in ToolEvent we put it in logs
model=get_model_from_kwargs(kwargs),
prompt=prompts[0],
# tags=tags # TODO
)

@debug_print_function_params
Expand Down Expand Up @@ -156,15 +161,18 @@ def on_chain_start(
metadata: Optional[Dict[str, Any]] = None,
**kwargs: Any,
) -> Any:
self.events.chain[str(run_id)] = ActionEvent(
params={
**serialized,
**inputs,
**({} if metadata is None else metadata),
**kwargs,
},
action_type="chain",
)
try:
self.events.chain[str(run_id)] = ActionEvent(
params={
**serialized,
**inputs,
**({} if metadata is None else metadata),
**kwargs,
},
action_type="chain",
)
except Exception as e:
logger.warning(e)

@debug_print_function_params
def on_chain_end(
Expand Down Expand Up @@ -240,6 +248,8 @@ def on_tool_end(
details=output,
)
self.ao_client.record(error_event)
else:
self.ao_client.record(tool_event)

@debug_print_function_params
def on_tool_error(
Expand Down Expand Up @@ -357,7 +367,13 @@ def on_retry(

@property
def session_id(self):
return self.ao_client.current_session_id
raise DeprecationWarning(
"session_id is deprecated in favor of current_session_ids"
)

@property
def current_session_ids(self):
return self.ao_client.current_session_ids


class AsyncLangchainCallbackHandler(AsyncCallbackHandler):
Expand Down
2 changes: 1 addition & 1 deletion agentops/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ def _flush_queue(self) -> None:
if not self.is_running:
return
with self.lock:
queue_copy = copy.deepcopy(self.queue) # Copy the current items
queue_copy = self.queue[:] # Copy the current items
self.queue = []

if len(queue_copy) > 0:
Expand Down
5 changes: 2 additions & 3 deletions agentops/time_travel.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import json
import yaml
import os
from .http_client import HttpClient
from .exceptions import ApiServerException
import os
from .helpers import singleton
from os import environ


@singleton
Expand Down Expand Up @@ -32,7 +31,7 @@ def __init__(self):

def fetch_time_travel_id(ttd_id):
try:
endpoint = environ.get("AGENTOPS_API_ENDPOINT", "https://api.agentops.ai")
endpoint = os.environ.get("AGENTOPS_API_ENDPOINT", "https://api.agentops.ai")
ttd_res = HttpClient.get(f"{endpoint}/v2/ttd/{ttd_id}")
if ttd_res.code != 200:
raise Exception(f"Failed to fetch TTD with status code {ttd_res.code}")
Expand Down
2 changes: 1 addition & 1 deletion docs/v0/logger.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ description: 'This document explains the use of the AgentOpsLogger

## AgentOps logger

The AgentsOps logger is quick and simple way of integrating your existing
The AgentOps logger is quick and simple way of integrating your existing
agent codebase with AgentOps. It allows you to use your current logs as events
by extending the built-in Python logging system to emit events to AgentOps.

Expand Down
2 changes: 1 addition & 1 deletion docs/v0/recording-events.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ From this point, simply call the .record() method in the AgentOps client:
ao_client.record(Event("event_type1"))
```

In AgentsOps, each session is associated with a number of "Events". Events have
In AgentOps, each session is associated with a number of "Events". Events have
must have an "event_type" which is any abitrary string of your choice. It might be something
like "OpenAI Call". Events can also have other information such as the parameters of the operation,
the returned data, alongside tags, etc.
Expand Down
Loading

0 comments on commit 4c53ec6

Please sign in to comment.