diff --git a/prompts/default/agent.system.tool.collaboration.md b/prompts/default/agent.system.tool.collaboration.md new file mode 100644 index 000000000..92fed1355 --- /dev/null +++ b/prompts/default/agent.system.tool.collaboration.md @@ -0,0 +1,52 @@ +### collaboration_tool + +Interact with the real-time collaborative document space. +Allows reading, writing (overwrite), and appending to shared documents. +Use this to collaborate with human users or other agents. +Default doc_id is "default". + +usage: + +1. Read document +~~~json +{ + "thoughts": [ + "Checking what is in the shared document..." + ], + "tool_name": "collaboration_tool", + "tool_args": { + "action": "read", + "doc_id": "default" + } +} +~~~ + +2. Append to document +~~~json +{ + "thoughts": [ + "Adding my analysis to the shared doc..." + ], + "tool_name": "collaboration_tool", + "tool_args": { + "action": "append", + "content": "Here is the summary of the data...", + "doc_id": "default" + } +} +~~~ + +3. Overwrite document +~~~json +{ + "thoughts": [ + "Clearing the doc and starting fresh..." + ], + "tool_name": "collaboration_tool", + "tool_args": { + "action": "write", + "content": "Meeting Agenda:\n1. Intro...", + "doc_id": "default" + } +} +~~~ diff --git a/prompts/default/agent.system.tools.md b/prompts/default/agent.system.tools.md index 43f35ea12..590ae46d4 100644 --- a/prompts/default/agent.system.tools.md +++ b/prompts/default/agent.system.tools.md @@ -15,3 +15,5 @@ {{ include './agent.system.tool.input.md' }} {{ include './agent.system.tool.browser.md' }} + +{{ include './agent.system.tool.collaboration.md' }} diff --git a/python/collaboration.py b/python/collaboration.py new file mode 100644 index 000000000..df4dc8a40 --- /dev/null +++ b/python/collaboration.py @@ -0,0 +1,32 @@ +from flask_socketio import SocketIO, emit, join_room, leave_room +from flask import request + +socketio = SocketIO(cors_allowed_origins="*") + +# In-memory store for documents: {doc_id: content} +documents = {} + +def init_collaboration(app): + socketio.init_app(app) + + @socketio.on('connect') + def handle_connect(): + pass + + @socketio.on('join_document') + def on_join(data): + room = data.get('doc_id', 'default') + join_room(room) + # Send current document state + content = documents.get(room, "") + emit('document_state', {'content': content}, room=request.sid) + + @socketio.on('update_document') + def on_update(data): + room = data.get('doc_id', 'default') + content = data.get('content', '') + documents[room] = content + # Broadcast to others in the room + emit('document_updated', {'content': content}, room=room, include_self=False) + + return socketio diff --git a/python/tools/collaboration_tool.py b/python/tools/collaboration_tool.py new file mode 100644 index 000000000..7a4e03ec2 --- /dev/null +++ b/python/tools/collaboration_tool.py @@ -0,0 +1,24 @@ +from python.helpers.tool import Tool, Response +from python.collaboration import documents, socketio + +class CollaborationTool(Tool): + async def execute(self, action, content="", doc_id="default", **kwargs): + if action == "read": + text = documents.get(doc_id, "") + return Response(message=f"Document content:\n{text}", break_loop=False) + + elif action == "write": + # Overwrite + documents[doc_id] = content + socketio.emit('document_updated', {'content': content}, room=doc_id) + return Response(message="Document updated.", break_loop=False) + + elif action == "append": + current = documents.get(doc_id, "") + new_content = current + "\n" + content + documents[doc_id] = new_content + socketio.emit('document_updated', {'content': new_content}, room=doc_id) + return Response(message="Appended to document.", break_loop=False) + + else: + return Response(message="Unknown action. Use read, write, or append.", break_loop=False) diff --git a/run_ui.py b/run_ui.py index bf297ee81..d68e7077b 100644 --- a/run_ui.py +++ b/run_ui.py @@ -10,6 +10,7 @@ from python.helpers.cloudflare_tunnel import CloudflareTunnel from python.helpers.extract_tools import load_classes_from_folder from python.helpers.api import ApiHandler from python.helpers.print_style import PrintStyle +from python.collaboration import init_collaboration # initialize the internal Flask server @@ -126,6 +127,9 @@ def run(): for handler in handlers: register_api_handler(app, handler) + # Initialize collaboration (SocketIO) + socketio = init_collaboration(app) + try: server = make_server( host=host, diff --git a/webui/collaboration.html b/webui/collaboration.html new file mode 100644 index 000000000..5063e33e2 --- /dev/null +++ b/webui/collaboration.html @@ -0,0 +1,65 @@ + + + + + + Collaboration Space + + + + +
+

Collaboration Space

+
Disconnected
+
+
+ +
+ + + + + diff --git a/webui/index.html b/webui/index.html index 808ca2791..6b47a60b1 100644 --- a/webui/index.html +++ b/webui/index.html @@ -351,6 +351,13 @@ + +