Skip to content

[Bug]: Can't run Agentops in .ipynb whereas the same code works in a .py file.Β #875

@Niharrrrrr

Description

@Niharrrrrr

Contact Details

niharmittal9185@gmail.com

πŸ“¦ Package Version

0.4.4

🎞️ Framework Version

CrewAI : 0.100.0

πŸ”Ž Describe the Bug

I am running the code :

`import agentops
from crewai import Agent, Crew, Process, Task,LLM
import openai
from openai import OpenAI
import os
from langchain_openai import ChatOpenAI
from dotenv import load_dotenv
from agentops import track_tool
load_dotenv()

agentops.init(api_key=os.getenv("AGENTOPS_API_KEY"),default_tags=['crewai'],auto_start_session=True)
OPENAI_API_KEY=os.getenv("OPENAI_API_KEY")
llm=LLM(api_key=OPENAI_API_KEY,model='gpt-4o')

Create specialized agents

researcher = Agent(
role="Market Research Specialist",
goal="Find comprehensive market data on emerging technologies",
backstory="You are an expert at discovering market trends and gathering data.",
llm=llm
)

analyst = Agent(
role="Market Analyst",
goal="Analyze market data and identify key opportunities",
backstory="You excel at interpreting market data and spotting valuable insights.",
llm=llm
)

Define their tasks

research_task = Task(
description="Research the current market landscape for AI-powered healthcare solutions",
expected_output="Comprehensive market data including key players, market size, and growth trends",
agent=researcher
)

analysis_task = Task(
description="Analyze the market data and identify the top 3 investment opportunities",
expected_output="Analysis report with 3 recommended investment opportunities and rationale",
agent=analyst,
context=[research_task]
)

Create the crew

market_analysis_crew = Crew(
agents=[researcher, analyst],
tasks=[research_task, analysis_task],
process=Process.sequential,
verbose=True
)

Run the crew

result = market_analysis_crew.kickoff()
print(result.raw)
`

When I run this in .py file it works I can see everything but I want to use this in my notebook itself. Agentops is not initializing in notebook , why is this happening and how to resolve?

🀝 Contribution

  • Yes, I'd be happy to submit a pull request with these changes.
  • I need some guidance on how to contribute.
  • I'd prefer the AgentOps team to handle this update.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions