pip install "praisonai[mongodb]"
export OPENAI_API_KEY=
export GITHUB_TOKEN=xxxxxxxx (Optional: if getting data from github repo)
from praisonaiagents import ContextAgent
agent = ContextAgent(llm="gpt-4o-mini", auto_analyze=False)
agent.start("https://github.com/MervinPraison/PraisonAI/ Need to add Authentication")
Knowledge
import os
from praisonaiagents import Agent, Task, PraisonAIAgents
# Ensure OpenAI API key is set
if not os.environ.get("OPENAI_API_KEY"):
raise ValueError("Please set the OPENAI_API_KEY environment variable")
def main():
# MongoDB knowledge configuration
mongodb_knowledge_config = {
"vector_store": {
"provider": "mongodb",
"config": {
"connection_string": "mongodb+srv://Username:Password@cluster2.bofm7.mywebsite.net/?retryWrites=true&w=majority&appName=Cluster2", # Replace with your MongoDB connection string
"database": "praisonai_knowledge",
"collection": "knowledge_base",
"use_vector_search": True # Enable Atlas Vector Search
}
},
"embedder": {
"provider": "openai",
"config": {
"model": "text-embedding-3-small",
"api_key": os.getenv("OPENAI_API_KEY")
}
}
}
# Create a knowledge agent with MongoDB knowledge store
knowledge_agent = Agent(
name="MongoDB Knowledge Agent",
role="Knowledge Specialist",
goal="Provide accurate information from MongoDB knowledge base",
backstory="""You are an expert knowledge specialist who can access and
retrieve information from a comprehensive MongoDB knowledge base. You excel
at finding relevant information, synthesizing knowledge from multiple sources,
and providing accurate, context-aware responses.""",
knowledge_config=mongodb_knowledge_config,
knowledge=[os.path.join(os.path.dirname(__file__), "llms.md")],
memory=True,
verbose=True,
llm="gpt-4o-mini"
)
# Create a research assistant agent
research_agent = Agent(
name="Research Assistant",
role="Research Assistant",
goal="Gather information and store it in the knowledge base",
backstory="""You are a research assistant who specializes in gathering
information from various sources and organizing it for storage in the
knowledge base. You ensure information is accurate, well-structured,
and properly categorized.""",
memory=True,
verbose=True,
llm="gpt-4o-mini"
)
# Create tasks for knowledge management
knowledge_tasks = [
Task(
description="""Research and store information about MongoDB Atlas Vector Search:
1. Gather comprehensive information about MongoDB Atlas Vector Search
2. Include technical specifications, use cases, and best practices
3. Store the information in the MongoDB knowledge base
4. Organize information by categories (features, performance, integration)
""",
expected_output="MongoDB Atlas Vector Search information stored in knowledge base",
agent=research_agent
),
Task(
description="""Research and store information about AI agent frameworks:
1. Research popular AI agent frameworks (LangChain, AutoGen, etc.)
2. Compare their features, capabilities, and use cases
3. Store comparative analysis in the knowledge base
4. Include code examples and best practices
""",
expected_output="AI agent framework comparison stored in knowledge base",
agent=research_agent
),
Task(
description="""Query the knowledge base for MongoDB information:
1. Search for information about MongoDB Atlas Vector Search
2. Extract key features and capabilities
3. Provide a comprehensive summary
4. Include technical recommendations
""",
expected_output="Comprehensive MongoDB Atlas Vector Search summary from knowledge base",
agent=knowledge_agent
),
Task(
description="""Query the knowledge base for AI agent framework information:
1. Search for information about AI agent frameworks
2. Compare different frameworks based on stored knowledge
3. Provide recommendations for different use cases
4. Include best practices and examples
""",
expected_output="AI agent framework comparison and recommendations from knowledge base",
agent=knowledge_agent
)
]
# Initialize the multi-agent system with MongoDB knowledge
print("🚀 Starting MongoDB Knowledge Management System...")
print("=" * 60)
knowledge_system = PraisonAIAgents(
agents=[research_agent, knowledge_agent],
tasks=knowledge_tasks,
memory=True,
verbose=True
)
# Execute the knowledge management pipeline
results = knowledge_system.start()
if __name__ == "__main__":
main()
from praisonaiagents import Agent, Task, PraisonAIAgents
from praisonaiagents.memory import Memory
from praisonaiagents.agent import ContextAgent
import pymongo
context_agent = ContextAgent(llm="gpt-4o-mini", auto_analyze=False)
context_output = context_agent.start("https://github.com/MervinPraison/PraisonAI/ Need to add Authentication")
mongodb_memory_config = {
"provider": "mongodb",
"config": {
"connection_string": "mongodb+srv://Username:Password@cluster2.bofm7.mywebsite.net/?retryWrites=true&w=majority&appName=Cluster2",
"database": "praisonai_memory",
"use_vector_search": True,
"max_pool_size": 50,
"min_pool_size": 10,
"server_selection_timeout": 5000
}
}
implementation_agent = Agent(
name="Implementation Agent",
role="Authentication Implementation Specialist",
goal="Implement authentication features based on project requirements",
backstory="Expert software implementer specializing in authentication systems, security features, and seamless integration with existing codebases",
memory=True,
llm="gpt-4o-mini",
)
implementation_task = Task(
description="Implement authentication features based on the project requirements from context analysis",
expected_output="Authentication implementation with code, configuration, and integration details",
agent=implementation_agent,
context=context_output,
)
implementation_system = PraisonAIAgents(
agents=[implementation_agent],
tasks=[implementation_task],
memory=True,
memory_config=mongodb_memory_config
)
results = implementation_system.start()
print(f"Results: {results}")