composer-agent 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. composer_agent-0.1.0/.gitignore +18 -0
  2. composer_agent-0.1.0/LICENSE +21 -0
  3. composer_agent-0.1.0/PKG-INFO +111 -0
  4. composer_agent-0.1.0/README.md +59 -0
  5. composer_agent-0.1.0/chat/__init__.py +0 -0
  6. composer_agent-0.1.0/chat/apps.py +6 -0
  7. composer_agent-0.1.0/chat/migrations/0001_initial.py +83 -0
  8. composer_agent-0.1.0/chat/migrations/__init__.py +0 -0
  9. composer_agent-0.1.0/chat/models.py +88 -0
  10. composer_agent-0.1.0/composer/__init__.py +97 -0
  11. composer_agent-0.1.0/composer/agent.py +1057 -0
  12. composer_agent-0.1.0/composer/image.py +216 -0
  13. composer_agent-0.1.0/composer/mcp.py +226 -0
  14. composer_agent-0.1.0/composer/persistence/__init__.py +3 -0
  15. composer_agent-0.1.0/composer/persistence/chat_session.py +336 -0
  16. composer_agent-0.1.0/composer/persistence/cli.py +16 -0
  17. composer_agent-0.1.0/composer/persistence/django_setup.py +38 -0
  18. composer_agent-0.1.0/composer/persistence/repository.py +195 -0
  19. composer_agent-0.1.0/composer/persistence/serializers.py +166 -0
  20. composer_agent-0.1.0/composer/stream.py +520 -0
  21. composer_agent-0.1.0/composer/stream_events.py +27 -0
  22. composer_agent-0.1.0/composer/thread.py +539 -0
  23. composer_agent-0.1.0/composer/thread_branch.py +287 -0
  24. composer_agent-0.1.0/composer/tool_hide.py +516 -0
  25. composer_agent-0.1.0/composer/tools.py +138 -0
  26. composer_agent-0.1.0/composer/vector.py +110 -0
  27. composer_agent-0.1.0/composer_site/__init__.py +0 -0
  28. composer_agent-0.1.0/composer_site/settings.py +43 -0
  29. composer_agent-0.1.0/composer_site/urls.py +1 -0
  30. composer_agent-0.1.0/composer_site/wsgi.py +7 -0
  31. composer_agent-0.1.0/docs/chat_persistence.md +323 -0
  32. composer_agent-0.1.0/pyproject.toml +105 -0
@@ -0,0 +1,18 @@
1
+ # Python-generated files
2
+ __pycache__/
3
+ .ipynb_checkpoints/
4
+ *.py[oc]
5
+ build/
6
+ dist/
7
+ wheels/
8
+ *.egg-info
9
+
10
+
11
+ # Virtual environments
12
+ .venv
13
+
14
+ # Django
15
+ db.sqlite3
16
+
17
+ # Environment variables
18
+ .env
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 MM21B038
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,111 @@
1
+ Metadata-Version: 2.4
2
+ Name: composer-agent
3
+ Version: 0.1.0
4
+ Summary: Thread-based agents with typed streaming, tool-hide rules, branch compression, and optional Django persistence
5
+ Project-URL: Homepage, https://github.com/MM21B038/composer
6
+ Project-URL: Documentation, https://github.com/MM21B038/composer/blob/main/docs/chat_persistence.md
7
+ Project-URL: Repository, https://github.com/MM21B038/composer
8
+ Project-URL: Issues, https://github.com/MM21B038/composer/issues
9
+ Author-email: MM21B038 <mg2464109@gmail.com>
10
+ License-Expression: MIT
11
+ License-File: LICENSE
12
+ Keywords: agents,langchain,llm,mcp,streaming
13
+ Classifier: Development Status :: 3 - Alpha
14
+ Classifier: Framework :: Django
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: License :: OSI Approved :: MIT License
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Programming Language :: Python :: 3.14
21
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
22
+ Requires-Python: >=3.12
23
+ Requires-Dist: deepagents>=0.6.3
24
+ Requires-Dist: langchain-core>=1.4.0
25
+ Requires-Dist: langchain-mcp-adapters>=0.2.2
26
+ Requires-Dist: langchain-openai>=1.2.1
27
+ Requires-Dist: langchain-openrouter>=0.2.3
28
+ Requires-Dist: langchain>=1.3.1
29
+ Requires-Dist: langgraph>=1.2.0
30
+ Requires-Dist: numpy>=2.0.0
31
+ Requires-Dist: pillow>=11.0.0
32
+ Requires-Dist: tiktoken>=0.13.0
33
+ Provides-Extra: all
34
+ Requires-Dist: django>=5.1; extra == 'all'
35
+ Requires-Dist: ipykernel>=7.2.0; extra == 'all'
36
+ Requires-Dist: jupyter>=1.1.1; extra == 'all'
37
+ Requires-Dist: pytest-django>=4.9; extra == 'all'
38
+ Requires-Dist: pytest>=8.0; extra == 'all'
39
+ Requires-Dist: python-dotenv>=1.0.0; extra == 'all'
40
+ Provides-Extra: dev
41
+ Requires-Dist: build>=1.2; extra == 'dev'
42
+ Requires-Dist: django>=5.1; extra == 'dev'
43
+ Requires-Dist: ipykernel>=7.2.0; extra == 'dev'
44
+ Requires-Dist: jupyter>=1.1.1; extra == 'dev'
45
+ Requires-Dist: pytest-django>=4.9; extra == 'dev'
46
+ Requires-Dist: pytest>=8.0; extra == 'dev'
47
+ Requires-Dist: python-dotenv>=1.0.0; extra == 'dev'
48
+ Requires-Dist: twine>=6.0; extra == 'dev'
49
+ Provides-Extra: django
50
+ Requires-Dist: django>=5.1; extra == 'django'
51
+ Description-Content-Type: text/markdown
52
+
53
+ # Composer
54
+
55
+ Thread-based agents with typed streaming, tool-hide rules, branch compression, and optional Django persistence.
56
+
57
+ ## Install
58
+
59
+ ```bash
60
+ pip install composer-agent
61
+ ```
62
+
63
+ With chat persistence (Django + SQLite):
64
+
65
+ ```bash
66
+ pip install composer-agent[django]
67
+ composer-migrate
68
+ ```
69
+
70
+ The default database path is `~/.composer/db.sqlite3`. Override with `COMPOSER_DB_PATH`.
71
+
72
+ ## Quick start
73
+
74
+ ```python
75
+ from composer import Agent, HumanMessage, SystemMessage, Thread
76
+
77
+ agent = Agent(model="...", base_url="...", api_key="...")
78
+ thread = Thread()
79
+ SystemMessage("You are a helpful assistant.") | thread
80
+ thread.append(HumanMessage("Hello"))
81
+ reply = thread.invoke(agent)
82
+ print(reply.content)
83
+ ```
84
+
85
+ ## Chat persistence
86
+
87
+ See [docs/chat_persistence.md](docs/chat_persistence.md) for the full guide on `ChatProject` and `ChatSession` — create/list/delete projects and sessions, incognito mode, branch graphs, and resuming conversations.
88
+
89
+ ```python
90
+ from composer import ChatProject, HumanMessage, SystemMessage
91
+
92
+ project = ChatProject.create("my-project")
93
+ session = project.new_session(name="main")
94
+ ```
95
+
96
+ ## Development
97
+
98
+ ```bash
99
+ uv sync --group dev
100
+ pytest
101
+ python manage.py migrate # uses ./db.sqlite3 in the repo checkout
102
+ ```
103
+
104
+ ## Publish
105
+
106
+ ```bash
107
+ uv sync --group dev
108
+ python -m build
109
+ twine upload --repository testpypi dist/* # test first
110
+ twine upload dist/* # production PyPI
111
+ ```
@@ -0,0 +1,59 @@
1
+ # Composer
2
+
3
+ Thread-based agents with typed streaming, tool-hide rules, branch compression, and optional Django persistence.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ pip install composer-agent
9
+ ```
10
+
11
+ With chat persistence (Django + SQLite):
12
+
13
+ ```bash
14
+ pip install composer-agent[django]
15
+ composer-migrate
16
+ ```
17
+
18
+ The default database path is `~/.composer/db.sqlite3`. Override with `COMPOSER_DB_PATH`.
19
+
20
+ ## Quick start
21
+
22
+ ```python
23
+ from composer import Agent, HumanMessage, SystemMessage, Thread
24
+
25
+ agent = Agent(model="...", base_url="...", api_key="...")
26
+ thread = Thread()
27
+ SystemMessage("You are a helpful assistant.") | thread
28
+ thread.append(HumanMessage("Hello"))
29
+ reply = thread.invoke(agent)
30
+ print(reply.content)
31
+ ```
32
+
33
+ ## Chat persistence
34
+
35
+ See [docs/chat_persistence.md](docs/chat_persistence.md) for the full guide on `ChatProject` and `ChatSession` — create/list/delete projects and sessions, incognito mode, branch graphs, and resuming conversations.
36
+
37
+ ```python
38
+ from composer import ChatProject, HumanMessage, SystemMessage
39
+
40
+ project = ChatProject.create("my-project")
41
+ session = project.new_session(name="main")
42
+ ```
43
+
44
+ ## Development
45
+
46
+ ```bash
47
+ uv sync --group dev
48
+ pytest
49
+ python manage.py migrate # uses ./db.sqlite3 in the repo checkout
50
+ ```
51
+
52
+ ## Publish
53
+
54
+ ```bash
55
+ uv sync --group dev
56
+ python -m build
57
+ twine upload --repository testpypi dist/* # test first
58
+ twine upload dist/* # production PyPI
59
+ ```
File without changes
@@ -0,0 +1,6 @@
1
+ from django.apps import AppConfig
2
+
3
+
4
+ class ChatConfig(AppConfig):
5
+ default_auto_field = "django.db.models.BigAutoField"
6
+ name = "chat"
@@ -0,0 +1,83 @@
1
+ # Generated by Django 6.0.6 on 2026-06-07 17:56
2
+
3
+ import django.db.models.deletion
4
+ import uuid
5
+ from django.db import migrations, models
6
+
7
+
8
+ class Migration(migrations.Migration):
9
+
10
+ initial = True
11
+
12
+ dependencies = [
13
+ ]
14
+
15
+ operations = [
16
+ migrations.CreateModel(
17
+ name='ChatSession',
18
+ fields=[
19
+ ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
20
+ ('name', models.CharField(blank=True, default='', max_length=255)),
21
+ ('config', models.JSONField(default=dict)),
22
+ ('active_branch_id', models.UUIDField()),
23
+ ('created_at', models.DateTimeField(auto_now_add=True)),
24
+ ('updated_at', models.DateTimeField(auto_now=True)),
25
+ ],
26
+ options={
27
+ 'ordering': ['-updated_at'],
28
+ },
29
+ ),
30
+ migrations.CreateModel(
31
+ name='Project',
32
+ fields=[
33
+ ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
34
+ ('name', models.CharField(max_length=255, unique=True)),
35
+ ('created_at', models.DateTimeField(auto_now_add=True)),
36
+ ('updated_at', models.DateTimeField(auto_now=True)),
37
+ ],
38
+ options={
39
+ 'ordering': ['name'],
40
+ },
41
+ ),
42
+ migrations.CreateModel(
43
+ name='BranchNodeRecord',
44
+ fields=[
45
+ ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
46
+ ('compressed_payload', models.JSONField(blank=True, null=True)),
47
+ ('compressed_through', models.PositiveIntegerField()),
48
+ ('visible_end', models.PositiveIntegerField(blank=True, null=True)),
49
+ ('child_order', models.JSONField(default=list)),
50
+ ('parent', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='children_nodes', to='chat.branchnoderecord')),
51
+ ('session', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='branch_nodes', to='chat.chatsession')),
52
+ ],
53
+ options={
54
+ 'ordering': ['compressed_through'],
55
+ },
56
+ ),
57
+ migrations.AddField(
58
+ model_name='chatsession',
59
+ name='project',
60
+ field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='sessions', to='chat.project'),
61
+ ),
62
+ migrations.CreateModel(
63
+ name='StoredMessage',
64
+ fields=[
65
+ ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
66
+ ('position', models.PositiveIntegerField()),
67
+ ('message_type', models.CharField(max_length=32)),
68
+ ('payload', models.JSONField()),
69
+ ('session', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='messages', to='chat.chatsession')),
70
+ ],
71
+ options={
72
+ 'ordering': ['position'],
73
+ },
74
+ ),
75
+ migrations.AddConstraint(
76
+ model_name='chatsession',
77
+ constraint=models.UniqueConstraint(condition=models.Q(('name', ''), _negated=True), fields=('project', 'name'), name='uniq_named_session_per_project'),
78
+ ),
79
+ migrations.AddConstraint(
80
+ model_name='storedmessage',
81
+ constraint=models.UniqueConstraint(fields=('session', 'position'), name='uniq_message_position_per_session'),
82
+ ),
83
+ ]
File without changes
@@ -0,0 +1,88 @@
1
+ import uuid
2
+
3
+ from django.db import models
4
+ from django.db.models import Q
5
+
6
+
7
+ class Project(models.Model):
8
+ id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
9
+ name = models.CharField(max_length=255, unique=True)
10
+ created_at = models.DateTimeField(auto_now_add=True)
11
+ updated_at = models.DateTimeField(auto_now=True)
12
+
13
+ class Meta:
14
+ ordering = ["name"]
15
+
16
+ def __str__(self) -> str:
17
+ return self.name
18
+
19
+
20
+ class ChatSession(models.Model):
21
+ id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
22
+ project = models.ForeignKey(
23
+ Project,
24
+ on_delete=models.CASCADE,
25
+ related_name="sessions",
26
+ )
27
+ name = models.CharField(max_length=255, blank=True, default="")
28
+ config = models.JSONField(default=dict)
29
+ active_branch_id = models.UUIDField()
30
+ created_at = models.DateTimeField(auto_now_add=True)
31
+ updated_at = models.DateTimeField(auto_now=True)
32
+
33
+ class Meta:
34
+ ordering = ["-updated_at"]
35
+ constraints = [
36
+ models.UniqueConstraint(
37
+ fields=["project", "name"],
38
+ condition=~Q(name=""),
39
+ name="uniq_named_session_per_project",
40
+ ),
41
+ ]
42
+
43
+ def __str__(self) -> str:
44
+ label = self.name or str(self.id)
45
+ return f"{self.project.name}:{label}"
46
+
47
+
48
+ class StoredMessage(models.Model):
49
+ session = models.ForeignKey(
50
+ ChatSession,
51
+ on_delete=models.CASCADE,
52
+ related_name="messages",
53
+ )
54
+ position = models.PositiveIntegerField()
55
+ message_type = models.CharField(max_length=32)
56
+ payload = models.JSONField()
57
+
58
+ class Meta:
59
+ ordering = ["position"]
60
+ constraints = [
61
+ models.UniqueConstraint(
62
+ fields=["session", "position"],
63
+ name="uniq_message_position_per_session",
64
+ ),
65
+ ]
66
+
67
+
68
+ class BranchNodeRecord(models.Model):
69
+ id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
70
+ session = models.ForeignKey(
71
+ ChatSession,
72
+ on_delete=models.CASCADE,
73
+ related_name="branch_nodes",
74
+ )
75
+ parent = models.ForeignKey(
76
+ "self",
77
+ on_delete=models.CASCADE,
78
+ null=True,
79
+ blank=True,
80
+ related_name="children_nodes",
81
+ )
82
+ compressed_payload = models.JSONField(null=True, blank=True)
83
+ compressed_through = models.PositiveIntegerField()
84
+ visible_end = models.PositiveIntegerField(null=True, blank=True)
85
+ child_order = models.JSONField(default=list)
86
+
87
+ class Meta:
88
+ ordering = ["compressed_through"]
@@ -0,0 +1,97 @@
1
+ """Composer — thread-based agents with typed streaming."""
2
+
3
+ __version__ = "0.1.0"
4
+
5
+ from .agent import (
6
+ Agent,
7
+ MCPClient,
8
+ MCPPromptInfo,
9
+ MCPResourceInfo,
10
+ StreamEvent,
11
+ StreamEventKind,
12
+ StreamEventProcessor,
13
+ ThinkingEvent,
14
+ AssistantEvent,
15
+ ToolCallEvent,
16
+ ToolResultEvent,
17
+ ToolCall,
18
+ ToolResult,
19
+ combine_tools,
20
+ extract_thinking,
21
+ extract_assistant_text,
22
+ )
23
+ from .tools import run_tool_call
24
+ from .vector import Vector
25
+ from .image import ImageAttach
26
+ from .thread import (
27
+ Thread,
28
+ HumanMessage,
29
+ ImageMessage,
30
+ AIMessage,
31
+ SystemMessage,
32
+ ToolMessage,
33
+ CompressedMessage,
34
+ Message,
35
+ EncoderType,
36
+ TokenCalculator,
37
+ )
38
+ from .tool_hide import (
39
+ ToolResultHideRule,
40
+ HideMode,
41
+ get_original_content,
42
+ is_hidden_for_model,
43
+ message_matches_rule,
44
+ resolve_full_tool_name,
45
+ restore_hidden_tool_messages,
46
+ )
47
+
48
+ __all__ = [
49
+ "Agent",
50
+ "Vector",
51
+ "MCPClient",
52
+ "MCPPromptInfo",
53
+ "MCPResourceInfo",
54
+ "Thread",
55
+ "HumanMessage",
56
+ "ImageMessage",
57
+ "ImageAttach",
58
+ "AIMessage",
59
+ "SystemMessage",
60
+ "ToolMessage",
61
+ "CompressedMessage",
62
+ "Message",
63
+ "EncoderType",
64
+ "TokenCalculator",
65
+ "HideMode",
66
+ "ToolResultHideRule",
67
+ "get_original_content",
68
+ "is_hidden_for_model",
69
+ "message_matches_rule",
70
+ "resolve_full_tool_name",
71
+ "restore_hidden_tool_messages",
72
+ "ThinkingEvent",
73
+ "AssistantEvent",
74
+ "ToolCallEvent",
75
+ "ToolResultEvent",
76
+ "StreamEvent",
77
+ "StreamEventKind",
78
+ "StreamEventProcessor",
79
+ "ToolCall",
80
+ "ToolResult",
81
+ "combine_tools",
82
+ "run_tool_call",
83
+ "extract_thinking",
84
+ "extract_assistant_text",
85
+ "ChatProject",
86
+ "ChatSession",
87
+ ]
88
+
89
+ _LAZY_IMPORTS = {"ChatProject", "ChatSession"}
90
+
91
+
92
+ def __getattr__(name: str):
93
+ if name in _LAZY_IMPORTS:
94
+ from .persistence import ChatProject, ChatSession
95
+
96
+ return {"ChatProject": ChatProject, "ChatSession": ChatSession}[name]
97
+ raise AttributeError(f"module {__name__!r} has no attribute {name!r}")