MCPcopy Create free account
hub / github.com/AgentOps-AI/agentops / Session

Class Session

agentops/legacy/__init__.py:22–61  ·  view source on GitHub ↗

This class provides compatibility with CrewAI >= 0.105.0, which uses an event-based integration pattern where it calls methods directly on the Session object: - create_agent(): Called when a CrewAI agent is created - record(): Called when a CrewAI tool is used - end_session():

Source from the content-addressed store, hash-verified

20
21
22class Session:
23 """
24 This class provides compatibility with CrewAI >= 0.105.0, which uses an event-based
25 integration pattern where it calls methods directly on the Session object:
26
27 - create_agent(): Called when a CrewAI agent is created
28 - record(): Called when a CrewAI tool is used
29 - end_session(): Called when a CrewAI run completes
30 """
31
32 def __init__(self, trace_context: Optional[TraceContext]):
33 self.trace_context = trace_context
34
35 @property
36 def span(self) -> Optional[Any]:
37 return self.trace_context.span if self.trace_context else None
38
39 @property
40 def token(self) -> Optional[Any]:
41 return self.trace_context.token if self.trace_context else None
42
43 def __del__(self):
44 if self.trace_context and self.trace_context.span and self.trace_context.span.is_recording():
45 if not self.trace_context.is_init_trace:
46 logger.warning(
47 f"Legacy Session (trace ID: {self.trace_context.span.get_span_context().span_id}) \
48was garbage collected but its trace might still be recording. Ensure legacy sessions are ended with end_session()."
49 )
50
51 def create_agent(self, name: Optional[str] = None, agent_id: Optional[str] = None, **kwargs: Any):
52 """Method for CrewAI >= 0.105.0 compatibility. Currently a no-op."""
53 pass
54
55 def record(self, event: Any = None):
56 """Method for CrewAI >= 0.105.0 compatibility. Currently a no-op."""
57 pass
58
59 def end_session(self, **kwargs: Any):
60 """Ends the session for CrewAI >= 0.105.0 compatibility. Calls the global legacy end_session."""
61 end_session(session_or_status=self, **kwargs)
62
63
64@deprecated("Use agentops.start_trace() instead.")

Callers 4

initMethod · 0.90
start_sessionFunction · 0.70

Calls

no outgoing calls

Used in the wild real call sites across dependent graphs

searching dependent graphs…