chore: update environment variables and improve agent configuration
This commit is contained in:
@@ -17,43 +17,52 @@ from dotenv import load_dotenv
|
||||
from src.models.models import Agent, Client, User
|
||||
|
||||
# Configurar logging
|
||||
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
||||
logging.basicConfig(
|
||||
level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s"
|
||||
)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def create_demo_agents():
|
||||
"""Create example agents for the demo client"""
|
||||
try:
|
||||
# Load environment variables
|
||||
load_dotenv()
|
||||
|
||||
|
||||
# Get database settings
|
||||
db_url = os.getenv("POSTGRES_CONNECTION_STRING")
|
||||
if not db_url:
|
||||
logger.error("Environment variable POSTGRES_CONNECTION_STRING not defined")
|
||||
return False
|
||||
|
||||
|
||||
# Connect to the database
|
||||
engine = create_engine(db_url)
|
||||
Session = sessionmaker(bind=engine)
|
||||
session = Session()
|
||||
|
||||
|
||||
try:
|
||||
# Obter o cliente demo pelo email do usuário
|
||||
demo_email = os.getenv("DEMO_EMAIL", "demo@exemplo.com")
|
||||
demo_user = session.query(User).filter(User.email == demo_email).first()
|
||||
|
||||
|
||||
if not demo_user or not demo_user.client_id:
|
||||
logger.error(f"Demo user not found or not associated with a client: {demo_email}")
|
||||
logger.error(
|
||||
f"Demo user not found or not associated with a client: {demo_email}"
|
||||
)
|
||||
return False
|
||||
|
||||
|
||||
client_id = demo_user.client_id
|
||||
|
||||
|
||||
# Verificar se já existem agentes para este cliente
|
||||
existing_agents = session.query(Agent).filter(Agent.client_id == client_id).all()
|
||||
existing_agents = (
|
||||
session.query(Agent).filter(Agent.client_id == client_id).all()
|
||||
)
|
||||
if existing_agents:
|
||||
logger.info(f"There are already {len(existing_agents)} agents for the client {client_id}")
|
||||
logger.info(
|
||||
f"There are already {len(existing_agents)} agents for the client {client_id}"
|
||||
)
|
||||
return True
|
||||
|
||||
|
||||
# Example agent definitions
|
||||
agents = [
|
||||
{
|
||||
@@ -69,11 +78,12 @@ def create_demo_agents():
|
||||
inform that you will consult a specialist and return soon.
|
||||
""",
|
||||
"config": {
|
||||
"api_key": uuid.uuid4(),
|
||||
"tools": [],
|
||||
"mcp_servers": [],
|
||||
"custom_tools": [],
|
||||
"sub_agents": []
|
||||
}
|
||||
"sub_agents": [],
|
||||
},
|
||||
},
|
||||
{
|
||||
"name": "Sales_Products",
|
||||
@@ -89,11 +99,12 @@ def create_demo_agents():
|
||||
the customer's needs before recommending a product.
|
||||
""",
|
||||
"config": {
|
||||
"api_key": uuid.uuid4(),
|
||||
"tools": [],
|
||||
"mcp_servers": [],
|
||||
"custom_tools": [],
|
||||
"sub_agents": []
|
||||
}
|
||||
"sub_agents": [],
|
||||
},
|
||||
},
|
||||
{
|
||||
"name": "FAQ_Bot",
|
||||
@@ -109,14 +120,15 @@ def create_demo_agents():
|
||||
appropriate support channel.
|
||||
""",
|
||||
"config": {
|
||||
"api_key": uuid.uuid4(),
|
||||
"tools": [],
|
||||
"mcp_servers": [],
|
||||
"custom_tools": [],
|
||||
"sub_agents": []
|
||||
}
|
||||
}
|
||||
"sub_agents": [],
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
# Create the agents
|
||||
for agent_data in agents:
|
||||
# Create the agent
|
||||
@@ -128,27 +140,32 @@ def create_demo_agents():
|
||||
model=agent_data["model"],
|
||||
api_key=agent_data["api_key"],
|
||||
instruction=agent_data["instruction"].strip(),
|
||||
config=agent_data["config"]
|
||||
config=agent_data["config"],
|
||||
)
|
||||
|
||||
|
||||
session.add(agent)
|
||||
logger.info(f"Agent '{agent_data['name']}' created for the client {client_id}")
|
||||
|
||||
logger.info(
|
||||
f"Agent '{agent_data['name']}' created for the client {client_id}"
|
||||
)
|
||||
|
||||
session.commit()
|
||||
logger.info(f"All example agents were created successfully for the client {client_id}")
|
||||
logger.info(
|
||||
f"All example agents were created successfully for the client {client_id}"
|
||||
)
|
||||
return True
|
||||
|
||||
|
||||
except SQLAlchemyError as e:
|
||||
session.rollback()
|
||||
logger.error(f"Database error when creating example agents: {str(e)}")
|
||||
return False
|
||||
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error when creating example agents: {str(e)}")
|
||||
return False
|
||||
finally:
|
||||
session.close()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
success = create_demo_agents()
|
||||
sys.exit(0 if success else 1)
|
||||
sys.exit(0 if success else 1)
|
||||
|
||||
@@ -62,7 +62,20 @@ def create_mcp_servers():
|
||||
],
|
||||
},
|
||||
"environments": {},
|
||||
"tools": ["sequentialthinking"],
|
||||
"tools": [
|
||||
{
|
||||
"id": "sequentialthinking",
|
||||
"name": "Sequential Thinking",
|
||||
"description": "Helps organize thoughts and break down complex problems through a structured workflow",
|
||||
"tags": ["thinking", "analysis", "problem-solving"],
|
||||
"examples": [
|
||||
"Help me analyze this problem",
|
||||
"Guide me through this decision making process",
|
||||
],
|
||||
"inputModes": ["text"],
|
||||
"outputModes": ["text"],
|
||||
}
|
||||
],
|
||||
"type": "community",
|
||||
"id": "4519dd69-9343-4792-af51-dc4d322fb0c9",
|
||||
"created_at": "2025-04-28T15:14:16.901236Z",
|
||||
@@ -76,87 +89,30 @@ def create_mcp_servers():
|
||||
},
|
||||
"environments": {},
|
||||
"tools": [
|
||||
"worker_list",
|
||||
"worker_get",
|
||||
"worker_put",
|
||||
"worker_delete",
|
||||
"worker_get_worker",
|
||||
"worker_logs_by_worker_name",
|
||||
"worker_logs_by_ray_id",
|
||||
"worker_logs_keys",
|
||||
"get_kvs",
|
||||
"kv_get",
|
||||
"kv_put",
|
||||
"kv_list",
|
||||
"kv_delete",
|
||||
"r2_list_buckets",
|
||||
"r2_create_bucket",
|
||||
"r2_delete_bucket",
|
||||
"r2_list_objects",
|
||||
"r2_get_object",
|
||||
"r2_put_object",
|
||||
"r2_delete_object",
|
||||
"d1_list_databases",
|
||||
"d1_create_database",
|
||||
"d1_delete_database",
|
||||
"d1_query",
|
||||
"durable_objects_list",
|
||||
"durable_objects_create",
|
||||
"durable_objects_delete",
|
||||
"durable_objects_list_instances",
|
||||
"durable_objects_get_instance",
|
||||
"durable_objects_delete_instance",
|
||||
"queues_list",
|
||||
"queues_create",
|
||||
"queues_delete",
|
||||
"queues_get",
|
||||
"queues_send_message",
|
||||
"queues_get_messages",
|
||||
"queues_update_consumer",
|
||||
"workers_ai_list_models",
|
||||
"workers_ai_get_model",
|
||||
"workers_ai_run_inference",
|
||||
"workers_ai_list_tasks",
|
||||
"workflows_list",
|
||||
"workflows_create",
|
||||
"workflows_delete",
|
||||
"workflows_get",
|
||||
"workflows_update",
|
||||
"workflows_execute",
|
||||
"templates_list",
|
||||
"templates_get",
|
||||
"templates_create_from_template",
|
||||
"w4p_list_dispatchers",
|
||||
"w4p_create_dispatcher",
|
||||
"w4p_delete_dispatcher",
|
||||
"w4p_get_dispatcher",
|
||||
"w4p_update_dispatcher",
|
||||
"bindings_list",
|
||||
"bindings_create",
|
||||
"bindings_update",
|
||||
"bindings_delete",
|
||||
"routing_list_routes",
|
||||
"routing_create_route",
|
||||
"routing_update_route",
|
||||
"routing_delete_route",
|
||||
"cron_list",
|
||||
"cron_create",
|
||||
"cron_update",
|
||||
"cron_delete",
|
||||
"zones_list",
|
||||
"zones_create",
|
||||
"zones_delete",
|
||||
"zones_get",
|
||||
"zones_check_activation",
|
||||
"secrets_list",
|
||||
"secrets_put",
|
||||
"secrets_delete",
|
||||
"versions_list",
|
||||
"versions_get",
|
||||
"versions_rollback",
|
||||
"wrangler_get_config",
|
||||
"wrangler_update_config",
|
||||
"analytics_get",
|
||||
{
|
||||
"id": "worker_list",
|
||||
"name": "List Workers",
|
||||
"description": "List all Cloudflare Workers in your account",
|
||||
"tags": ["workers", "cloudflare"],
|
||||
"examples": [
|
||||
"List all my workers",
|
||||
"Show me my Cloudflare workers",
|
||||
],
|
||||
"inputModes": ["text"],
|
||||
"outputModes": ["application/json"],
|
||||
},
|
||||
{
|
||||
"id": "worker_get",
|
||||
"name": "Get Worker",
|
||||
"description": "Get details of a specific Cloudflare Worker",
|
||||
"tags": ["workers", "cloudflare"],
|
||||
"examples": [
|
||||
"Show me details of worker X",
|
||||
"Get information about worker Y",
|
||||
],
|
||||
"inputModes": ["text"],
|
||||
"outputModes": ["application/json"],
|
||||
},
|
||||
],
|
||||
"type": "official",
|
||||
"id": "9138d1a2-24e6-4a75-87b0-bfa4932273e8",
|
||||
@@ -172,7 +128,32 @@ def create_mcp_servers():
|
||||
"env": {"BRAVE_API_KEY": "env@@BRAVE_API_KEY"},
|
||||
},
|
||||
"environments": {"BRAVE_API_KEY": "env@@BRAVE_API_KEY"},
|
||||
"tools": ["brave_web_search", "brave_local_search"],
|
||||
"tools": [
|
||||
{
|
||||
"id": "brave_web_search",
|
||||
"name": "Web Search",
|
||||
"description": "Perform web searches using Brave Search",
|
||||
"tags": ["search", "web"],
|
||||
"examples": [
|
||||
"Search for Python documentation",
|
||||
"Find information about AI",
|
||||
],
|
||||
"inputModes": ["text"],
|
||||
"outputModes": ["application/json"],
|
||||
},
|
||||
{
|
||||
"id": "brave_local_search",
|
||||
"name": "Local Search",
|
||||
"description": "Search for local businesses and places",
|
||||
"tags": ["search", "local"],
|
||||
"examples": [
|
||||
"Find restaurants near me",
|
||||
"Search for hotels in New York",
|
||||
],
|
||||
"inputModes": ["text"],
|
||||
"outputModes": ["application/json"],
|
||||
},
|
||||
],
|
||||
"type": "official",
|
||||
"id": "416c94d7-77f5-43f4-8181-aeb87934ecbf",
|
||||
"created_at": "2025-04-28T15:20:07.647225Z",
|
||||
|
||||
Reference in New Issue
Block a user