Skip to content

import error #605

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

Closed
SkalaFrost opened this issue Jun 5, 2025 · 14 comments · Fixed by #610
Closed

import error #605

SkalaFrost opened this issue Jun 5, 2025 · 14 comments · Fixed by #610

Comments

@SkalaFrost
Copy link

I encountered an error while running the example.
Package version: 0.0.99
Error message:
ImportError: cannot import name 'Memory' from 'praisonaiagents.memory' (unknown location)

@MervinPraison
Copy link
Owner

@SkalaFrost, can you please provide me with the full code so I can try to test it?

Also, did you follow this documentation? https://docs.praison.ai/docs/concepts/memory

Thank you.

@SkalaFrost
Copy link
Author

SkalaFrost commented Jun 5, 2025

Sure @MervinPraisonm
code:
`from praisonaiagents.agents.agents import Agent, Task, PraisonAIAgents
from praisonaiagents.llm.llm import LLM
import os
import json
from dotenv import load_dotenv
load_dotenv()
def setup_llm():
config = {
"model": os.getenv('OPENAI_MODEL', "gpt-4o-mini"),
"api_key": os.getenv('OPENAI_API_KEY'),
"temperature": 0.7,
"max_tokens": 2000
}
base_url = os.getenv('OPENAI_BASE_URL')
if base_url:
config["base_url"] = base_url
return LLM(**config)

blog_agent = Agent(
role="Blog Writer",
goal="Write a blog post about AI",
backstory="Expert at writing blog posts",
llm=setup_llm(),
)
blog_task = Task(
description="Write a blog post about AI trends",
expected_output="Well-written blog post about AI trends",
agent=blog_agent
)
agents = PraisonAIAgents(
agents=[blog_agent],
tasks=[blog_task],
memory=True
)
result = agents.start()
print(result)`

Error:
Traceback (most recent call last): File "\test.py", line 1, in <module> from praisonaiagents.agents.agents import Agent, Task, PraisonAIAgents ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "\.venv\Lib\site-packages\praisonaiagents\__init__.py", line 14, in <module> from .session import Session File "\.venv\Lib\site-packages\praisonaiagents\session.py", line 12, in <module> from .memory import Memory ImportError: cannot import name 'Memory' from 'praisonaiagents.memory' (unknown location)

@dev-anthonyrae
Copy link

I get the same erroras SkalaFrost when trying to run the single agent example code.

@DracoBlue
Copy link

The praisonaiagents pip package is broken in latest versions (until 0.0.99 at least).

Try:

pip install praisonaiagents==0.0.96

and it will work.

@sureshtmca
Copy link

like memory, guardrail is also getting same import error

@MervinPraison
Copy link
Owner

MervinPraison commented Jun 5, 2025

@SkalaFrost @dev-anthonyrae @DracoBlue The bug has been fixed. Please upgrade to the latest version now and it should work

if you want to use litellm config and memory then you need to use

pip install -U "praisonaiagents[llm,memory]"

Please let me know if you still have issues. Happy to review and fix it quickly.

Here is the working code

from praisonaiagents import Agent, Task, PraisonAIAgents
import os
from dotenv import load_dotenv

load_dotenv()

llm_config = {
    "model": "openai/gpt-4o-mini",
    "api_key": os.getenv('OPENAI_API_KEY'),
    "temperature": 0.7,
    "max_tokens": 2000
}

blog_agent = Agent(
    role="Blog Writer",
    goal="Write a blog post about AI",
    backstory="Expert at writing blog posts",
    llm=llm_config,
)

blog_task = Task(
    description="Write a blog post about AI trends in 1 paragraph",
    expected_output="Well-written blog post about AI trends",
    agent=blog_agent
)

agents = PraisonAIAgents(
    agents=[blog_agent],
    tasks=[blog_task],
    memory=True
)

result = agents.start()

Docs :

How to use Models and config: https://docs.praison.ai/docs/models
How to use Memory: https://docs.praison.ai/docs/concepts/memory

Note: I am also working on making the memory more efficient. So stay tuned. Thank you

@MervinPraison
Copy link
Owner

@sureshtmca can you please post your code you are running, then i could test it at my end. thank you

@MervinPraison
Copy link
Owner

@sureshtmca Please try this guardrail code

Note : I include 5 words as a guardrail test below. Remove that 5 words from the code and it will allow the agent to run.

This is just an example

from praisonaiagents import Agent

def validate_content(data):
    if len(str(data)) < 50:
        return False, "Content too short"
    return True, data

agent = Agent(
    instructions="You are a writer",
    guardrail=validate_content,
    max_guardrail_retries=1
)

agent.start("Write a welcome message with 5 words")

with multi agents

from praisonaiagents import Agent, Task, TaskOutput, PraisonAIAgents
from typing import Tuple, Any

def validate_content(task_output: TaskOutput) -> Tuple[bool, Any]:
    if len(task_output.raw) < 50:
        return False, "Content too short"
    return True, task_output

agent = Agent(
    instructions="You are a writer",
)

task = Task(
    description="Write a welcome message 5 words",
    guardrail=validate_content,
    agent=agent
)

praison_agents = PraisonAIAgents(agents=[agent], tasks=[task])

praison_agents.start()

@Ucag
Copy link

Ucag commented Jun 5, 2025

Same import error. Using uv as package manager.

uv init projectname
cd projectname
uv add ""praisonaiagents[llm,memory]"

main.py

from praisonaiagents import Agent, PraisonAIAgents
from config import small_llm_config


# Create a simple agent
summarise_agent = Agent(
    instructions="Summarise Photosynthesis",
    llm=small_llm_config,
    verbose=True,
)

# Run the agent
agents = PraisonAIAgents(agents=[summarise_agent])
agents.start()

error

Traceback (most recent call last):
  File "/Users/ucag/practice/south_extract/./summarize_agent.py", line 1, in <module>
    from praisonaiagents import Agent, PraisonAIAgents
  File "/Users/ucag/practice/south_extract/.venv/lib/python3.11/site-packages/praisonaiagents/__init__.py", line 14, in <module>
    from .session import Session
  File "/Users/ucag/practice/south_extract/.venv/lib/python3.11/site-packages/praisonaiagents/session.py", line 12, in <module>
    from .memory import Memory
ImportError: cannot import name 'Memory' from 'praisonaiagents.memory' (unknown location)

By the way, version resolved by uv is

"praisonaiagents[llm,memory]>=0.0.99",

@MervinPraison
Copy link
Owner

MervinPraison commented Jun 5, 2025

@claude, review this error and propose a solution fix for this

also in memory.py consider this, it should work both with litellm and without litellm

Here is the change below

-    # Use OpenAI client from main.py
-    from ..main import Client
+    # Use LiteLLM for consistency with the rest of the codebase
+    import litellm

-    response = client.chat.completions.create(
-        model=llm or "gpt-4o",
+    # Convert model name if it's in litellm format
+    model_name = llm or "gpt-4o-mini"
+    response = litellm.completion(
+        model=model_name,

Copy link
Contributor

claude bot commented Jun 5, 2025

Claude finished @MervinPraison's task in 3m 14s —— View jobclaude/issue-605-20250605_165941Create PR ➔


Memory Import Error Fix Complete ✅

Todo List:

  • Investigate current memory.py implementation and import structure
  • Check session.py import statement
  • Analyze package structure and init.py files
  • Implement litellm compatibility changes as suggested
  • Ensure backward compatibility for non-litellm usage
  • Test import chain works correctly
  • Commit the fix

Summary of Changes

Root Cause: The Memory class was properly defined but had dependency issues with OpenAI client imports that weren't handling optional dependencies correctly.

Fix Applied:

  1. Added litellm compatibility with fallback chain:

    • ✅ Added LITELLM_AVAILABLE flag for dependency detection
    • ✅ Implemented litellm → openai → graceful degradation pattern
    • ✅ Updated all 4 locations where embeddings/LLM calls are made
  2. Enhanced package exports:

    • ✅ Added Memory to main package __init__.py exports
    • ✅ Users can now import as from praisonaiagents import Memory
  3. Improved error handling:

    • ✅ Graceful degradation when neither litellm nor openai is available
    • ✅ Proper logging for dependency issues
    • ✅ Backward compatibility maintained

Files Modified:

  • src/praisonai-agents/praisonaiagents/memory/memory.py - Core fix with litellm compatibility
  • src/praisonai-agents/praisonaiagents/__init__.py - Added Memory export

Testing:
Created comprehensive test suite (test_comprehensive_import.py) that verifies:

  • ✅ Original failing import: from praisonaiagents.agents.agents import Agent, Task, PraisonAIAgents
  • ✅ Direct memory import: from praisonaiagents.memory import Memory
  • ✅ Package root import: from praisonaiagents import Memory
  • ✅ Memory instantiation and basic operations

The fix maintains backward compatibility while adding the requested litellm integration with proper fallbacks. Users should now be able to install and use praisonaiagents without import errors.


@MervinPraison
Copy link
Owner

@SkalaFrost @dev-anthonyrae @DracoBlue @sureshtmca @Ucag Please upgrade to the latest version and the issue has been fixed.

If you still face issue, please raise the issue again or reopen this issue with the full code and output.

Thanks for your support.

@dev-anthonyrae
Copy link

Thanks @MervinPraison for the prompt fix!

@sureshtmca
Copy link

i could not keep calm without saying this. the structure of output generated from Agents and the validation of output (without user's much efforts) with instruction on reflection, is just just beautiful. You are awesome @MervinPraison

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants