feat: add support for agent and project on API
dipi.evil committed
Dec 19, 2025 at 10:08 UTC
5a63cf7bfbca1ab9fe2e174d9a220d063152de60
1 file changed
+12
-1
python/api/api_message.py
+12
-1
@@ -5,6 +5,7 @@ from agent import AgentContext, UserMessage, AgentContextType
5
from python.helpers.api import ApiHandler, Request, Response
6
from python.helpers import files
7
from python.helpers.print_style import PrintStyle
8
+from python.helpers.projects import activate_project
9
from werkzeug.utils import secure_filename
10
from initialize import initialize_agent
11
import threading
@@ -33,6 +34,13 @@ class ApiMessage(ApiHandler):
34
message = input.get("message", "")
35
attachments = input.get("attachments", [])
36
lifetime_hours = input.get("lifetime_hours", 24) # Default 24 hours
37
+ project_name = input.get("project_name", None)
38
+ agent_profile = input.get("agent_profile", None)
39
+
40
+ # Initialize agent if profile provided
41
+ override_settings = {}
42
+ if agent_profile:
43
+ override_settings["agent_profile"] = agent_profile
44
45
if not message:
46
return Response('{"error": "Message is required"}', status=400, mimetype="application/json")
@@ -72,11 +80,14 @@ class ApiMessage(ApiHandler):
80
if not context:
81
return Response('{"error": "Context not found"}', status=404, mimetype="application/json")
82
else:
75
- config = initialize_agent()
83
+ config = initialize_agent(override_settings=override_settings)
84
context = AgentContext(config=config, type=AgentContextType.USER)
85
AgentContext.use(context.id)
86
context_id = context.id
87
88
+ if project_name:
89
+ activate_project(context_id, project_name)
90
+
91
# Update chat lifetime
92
with self._cleanup_lock:
93
self._chat_lifetimes[context_id] = datetime.now() + timedelta(hours=lifetime_hours)