-
Notifications
You must be signed in to change notification settings - Fork 240
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
NoSessionException when user does not init() #307
Conversation
this fixes it in the SDK but we still need to determine why we were being called at all if nothing agentops was in the script |
as is, this breaks a lot of tests. i think this is bnot sending the first call to agentops |
Codecov ReportAttention: Patch coverage is
Flags with carried forward coverage won't be shown. Click here to find out more.
|
I refactored how state is being managed and it fixed the tests. this is now working as expected with agentops alone and with crew |
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.
Some questions about design. We can skip if this is urgent
Is this good to go @bboynton97 ? |
"If multiple sessions exist, you must use session.function(). Example: session.add_tags(...) instead " | ||
"of agentops.add_tags(...). More info: " | ||
"https://docs.agentops.ai/v1/concepts/core-concepts#session-management" | ||
f"Multiple sessions detected. You must use session.{calling_function}(). More info: https://docs.agentops.ai/v1/concepts/core-concepts#session-management" |
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.
nice!
Also fixed #308 🎉 |
📥 Pull Request
📘 Description
The sessions overhaul made it such that we are expecting a session when user never calls init(). For crew this shows up as @track_agent erroring bc "No session". safe_get_session() raises an error when no session exists, but no session should exist bc user never inits. Affects more than @track_agent
🎯 Goal
only check for session when init() called (global is_initialized = True)
🔍 Additional Context
User complaining in Discord and I recreated in examples/crew/job_posting.py
🧪 Testing
TODO
Thank you for your contribution to Agentops!
NoSessionException Traceback (most recent call last)
File ~/Desktop/agentops/AgentOps-AI/agentops/env/lib/python3.12/site-packages/agentops/meta_client.py:53, in handle_exceptions..wrapper(self, *args, **kwargs)
52 try:
---> 53 return method(self, *args, **kwargs)
54 except Exception as e:
File ~/Desktop/agentops/AgentOps-AI/agentops/env/lib/python3.12/site-packages/agentops/client.py:566, in Client._safe_get_session(self)
565 if len(self._sessions) == 0:
--> 566 raise NoSessionException("No session exists")
568 elif len(self._sessions) > 1:
NoSessionException: No session exists
During handling of the above exception, another exception occurred:
IndexError Traceback (most recent call last)
File ~/Desktop/agentops/AgentOps-AI/agentops/env/lib/python3.12/site-packages/agentops/meta_client.py:53, in handle_exceptions..wrapper(self, *args, **kwargs)
52 try:
---> 53 return method(self, *args, **kwargs)
54 except Exception as e:
File ~/Desktop/agentops/AgentOps-AI/agentops/env/lib/python3.12/site-packages/agentops/client.py:455, in Client.create_agent(self, name, agent_id, session)
453 else:
454 # if no session passed, assume single session
--> 455 session = self._safe_get_session()
456 session.create_agent(name=name, agent_id=agent_id)
File ~/Desktop/agentops/AgentOps-AI/agentops/env/lib/python3.12/site-packages/agentops/meta_client.py:61, in handle_exceptions..wrapper(self, *args, **kwargs)
57 if config is not None:
58 type(self).send_exception_to_server(
59 e,
60 self.config._api_key,
---> 61 self._sessions[0], # TODO: find which session caused exception
62 )
63 raise e
IndexError: list index out of range
During handling of the above exception, another exception occurred:
IndexError Traceback (most recent call last)
Cell In[5], line 15
12 specific_benefits = input("What are specific_benefits you offer?\n")
14 # Create Agents
---> 15 researcher_agent = agents.research_agent()
16 writer_agent = agents.writer_agent()
17 review_agent = agents.review_agent()
Cell In[3], line 13
12 def research_agent(self):
---> 13 return Agent(
14 role="Research Analyst",
15 goal="Analyze the company website and provided description to extract insights on culture, values, and specific needs.",
16 tools=[web_search_tool, serper_dev_tool],
17 backstory="Expert in analyzing company cultures and identifying key values and needs from various sources, including websites and brief descriptions.",
18 verbose=True,
19 )
File ~/Desktop/agentops/AgentOps-AI/agentops/env/lib/python3.12/site-packages/agentops/agent.py:26, in track_agent..decorator..new_init(self, *args, **kwargs)
23 if session is not None:
24 self.agent_ops_session_id = session.session_id
---> 26 Client().create_agent(
27 name=self.agent_ops_agent_name,
28 agent_id=self.agent_ops_agent_id,
29 session=session,
30 )
31 except AttributeError as e:
32 logger.warning(
33 "Failed to track an agent. This often happens if agentops.init() was not "
34 "called before initializing an agent with the @track_agent decorator."
35 )
File ~/Desktop/agentops/AgentOps-AI/agentops/env/lib/python3.12/site-packages/agentops/meta_client.py:61, in handle_exceptions..wrapper(self, *args, **kwargs)
56 config = getattr(self, "config", None)
57 if config is not None:
58 type(self).send_exception_to_server(
59 e,
60 self.config._api_key,
---> 61 self._sessions[0], # TODO: find which session caused exception
62 )
63 raise e
IndexError: list index out of range