camel-ai / camel

🐫 CAMEL: Finding the Scaling Law of Agents. A multi-agent framework. https://www.camel-ai.org
https://docs.camel-ai.org/
Apache License 2.0
5.44k stars 671 forks source link

[Feature Request] `Message` refactor #613

Open Wendong-Fan opened 4 months ago

Wendong-Fan commented 4 months ago

Required prerequisites

Motivation

learn from standards like FIPA and XMPP, refactor Message to make it more scalable to multi-agent communication

Solution

Requirements on agents:

Agents should send not-understood if they receive a message that they do not recognise or they are unable to process the content of the message. Agents must be prepared to receive and properly handle a not-understood message from other agents.

message attributes:

message types:

Information passing

Requesting information

Negotiation

Action performing

Error handling

Structured Output:

output_file: File path for storing messag output.
output_json: Pydantic model for structuring JSON output.
output_pydantic: Pydantic model for task output.

https://github.com/outlines-dev/outlines

https://github.com/jxnl/instructor

https://github.com/argilla-io/distilabel

Message Storage:

SQLLite

MySQL

PostgreSQL https://www.postgresql.org/

PostgreSQL supports complex data types such as JSON and JSONB, which can be useful for storing the structured message content with varied data types (text, image, audio, video, function_calling, etc.). It’s also highly extensible, allowing you to define custom functions, data types, and operators that can be very useful for your specific use case.

Example Schema Design in PostgreSQL:

CREATE TABLE agents (
    agent_id SERIAL PRIMARY KEY,
    role_name VARCHAR(255),
    role_type VARCHAR(255)
);

CREATE TABLE messages (
    message_id UUID PRIMARY KEY,
    sender_id INTEGER REFERENCES agents(agent_id),
    receiver_ids INTEGER[] REFERENCES agents(agent_id),
    content JSONB,
    reply_with UUID[],
    in_reply_to UUID[],
    envelope JSONB,
    language VARCHAR(255),
    ontology VARCHAR(255),
    reply_by TIMESTAMP,
    protocol JSONB,
    conversation_id UUID
);

Draft implementation for Message class:

from dataclasses import dataclass, field
from typing import Any, Dict, List, Tuple, Union
import uuid

@data. class
class Message:
    message_id: str = field(default_factory=lambda: str(uuid.uuid4()))
    type: str
    sender: Tuple[str, str]  # (role_name, role_type)
    receiver: Union[str, Tuple[str, ...]]  # Single agent or tuple of agents
    subject: str
    content: Any  # Could be text, image, audio, video, function_calling
    reply_with: List[str] = field(default_factory=list)
    in_reply_to: List[str] = field(default_factory=list)
    envelope: Dict[str, Any] = field(default_factory=dict)
    language: str
    ontology: str
    reply_by: str  # Time/date expression
    protocol: Dict[str, str] = field(default_factory=lambda: {"schema": "MIME"})
    conversation_id: str = field(default_factory=lambda: str(uuid.uuid4()))
    structured_output: Any = None  # Placeholder for structured output models

Discussion:

also add verbose?

unify current CAMEL message and response into 1?

Alternatives

No response

Additional context

No response

onemquan commented 2 months ago

add openai message ref: https://github.com/openai/openai-python/blob/af8f606b3eef1af99f98929847f1b5baf19171ae/src/openai/types/beta/threads/message.py