crystalplane 0.1.0__py3-none-any.whl
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.
- crystalplane/__init__.py +32 -0
- crystalplane/__main__.py +4 -0
- crystalplane/adapters/__init__.py +3 -0
- crystalplane/adapters/crewai.py +40 -0
- crystalplane/adapters/langchain.py +51 -0
- crystalplane/adapters/openai.py +162 -0
- crystalplane/archive_crawler.py +447 -0
- crystalplane/cache.py +106 -0
- crystalplane/cli.py +243 -0
- crystalplane/client.py +416 -0
- crystalplane/crawler.py +353 -0
- crystalplane/mcp_bridge.py +189 -0
- crystalplane/rate_limiter.py +120 -0
- crystalplane/research_lattice.py +546 -0
- crystalplane-0.1.0.dist-info/METADATA +62 -0
- crystalplane-0.1.0.dist-info/RECORD +19 -0
- crystalplane-0.1.0.dist-info/WHEEL +5 -0
- crystalplane-0.1.0.dist-info/entry_points.txt +2 -0
- crystalplane-0.1.0.dist-info/top_level.txt +1 -0
crystalplane/__init__.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Crystalplane — Hermetic Slim Runtime Client for AI Agent Systems
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from crystalplane.client import (
|
|
6
|
+
AssembledCrystal,
|
|
7
|
+
CrystalClient,
|
|
8
|
+
CrystalClientError,
|
|
9
|
+
RegistrationResult,
|
|
10
|
+
Shard,
|
|
11
|
+
)
|
|
12
|
+
from crystalplane.cache import ShardCache
|
|
13
|
+
from crystalplane.rate_limiter import RateLimiter
|
|
14
|
+
from crystalplane.crawler import SkillCrawler
|
|
15
|
+
from crystalplane.archive_crawler import ArchiveBookCrawler
|
|
16
|
+
from crystalplane.research_lattice import ResearchLatticeEngine
|
|
17
|
+
|
|
18
|
+
__version__ = "0.1.0"
|
|
19
|
+
__all__ = [
|
|
20
|
+
"CrystalClient",
|
|
21
|
+
"CrystalClientError",
|
|
22
|
+
"Shard",
|
|
23
|
+
"AssembledCrystal",
|
|
24
|
+
"RegistrationResult",
|
|
25
|
+
"ShardCache",
|
|
26
|
+
"RateLimiter",
|
|
27
|
+
"SkillCrawler",
|
|
28
|
+
"ArchiveBookCrawler",
|
|
29
|
+
"ResearchLatticeEngine",
|
|
30
|
+
"__version__",
|
|
31
|
+
]
|
|
32
|
+
|
crystalplane/__main__.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Crystalplane — CrewAI Tool Adapter
|
|
3
|
+
Provides native CrewAI BaseTool implementations.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
from typing import Any, List, Optional
|
|
9
|
+
|
|
10
|
+
from crystalplane.client import CrystalClient
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def get_crewai_tools(client: CrystalClient) -> List[Any]:
|
|
14
|
+
"""Returns CrewAI compatible BaseTool instances."""
|
|
15
|
+
try:
|
|
16
|
+
from crewai.tools import tool
|
|
17
|
+
except ImportError:
|
|
18
|
+
raise ImportError(
|
|
19
|
+
"CrewAI is not installed. Run `pip install crewai` or `pip install 'crystalplane[crewai]'`."
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
@tool("Search Crystalplane Knowledge")
|
|
23
|
+
def search_shards(query: str, domain: Optional[str] = None) -> str:
|
|
24
|
+
"""Search Crystalplane for authoritative skills, directives, or knowledge shards by keyword."""
|
|
25
|
+
from crystalplane.adapters.openai import execute_tool_call
|
|
26
|
+
return execute_tool_call(client, "crystal_search", {"query": query, "domain": domain})
|
|
27
|
+
|
|
28
|
+
@tool("Get Shard by ID")
|
|
29
|
+
def get_shard(shard_id: str) -> str:
|
|
30
|
+
"""Retrieve full authoritative markdown text of a specific Shard by its ID."""
|
|
31
|
+
from crystalplane.adapters.openai import execute_tool_call
|
|
32
|
+
return execute_tool_call(client, "crystal_get_shard", {"shard_id": shard_id})
|
|
33
|
+
|
|
34
|
+
@tool("Assemble Context Crystal")
|
|
35
|
+
def assemble_crystal(query: str, max_tokens: int = 2048) -> str:
|
|
36
|
+
"""Dynamically assemble composite prompt injection context across shards within a token budget."""
|
|
37
|
+
from crystalplane.adapters.openai import execute_tool_call
|
|
38
|
+
return execute_tool_call(client, "crystal_assemble", {"query": query, "max_tokens": max_tokens})
|
|
39
|
+
|
|
40
|
+
return [search_shards, get_shard, assemble_crystal]
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Crystalplane — LangChain & LangGraph Adapter
|
|
3
|
+
Provides native LangChain BaseTool and Retriever components.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
from typing import Any, List, Optional
|
|
9
|
+
|
|
10
|
+
from crystalplane.client import CrystalClient
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def get_crystal_tools(client: CrystalClient) -> List[Any]:
|
|
14
|
+
"""Returns a list of LangChain BaseTool instances bound to the given CrystalClient."""
|
|
15
|
+
try:
|
|
16
|
+
from langchain_core.tools import tool
|
|
17
|
+
except ImportError:
|
|
18
|
+
raise ImportError(
|
|
19
|
+
"LangChain is not installed. Run `pip install langchain-core` or `pip install 'crystalplane[langchain]'`."
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
@tool
|
|
23
|
+
def crystal_search(query: str, domain: Optional[str] = None, limit: int = 5) -> str:
|
|
24
|
+
"""Search Crystalplane for authoritative skill and knowledge shards by keywords."""
|
|
25
|
+
from crystalplane.adapters.openai import execute_tool_call
|
|
26
|
+
return execute_tool_call(client, "crystal_search", {"query": query, "domain": domain, "limit": limit})
|
|
27
|
+
|
|
28
|
+
@tool
|
|
29
|
+
def crystal_get_shard(shard_id: str) -> str:
|
|
30
|
+
"""Retrieve the complete authoritative markdown content and metadata for a specific Shard by ID."""
|
|
31
|
+
from crystalplane.adapters.openai import execute_tool_call
|
|
32
|
+
return execute_tool_call(client, "crystal_get_shard", {"shard_id": shard_id})
|
|
33
|
+
|
|
34
|
+
@tool
|
|
35
|
+
def crystal_assemble(query: str, max_tokens: int = 2048) -> str:
|
|
36
|
+
"""Assemble a Composite Skill Crystal within a token budget and return the compiled prompt injection."""
|
|
37
|
+
from crystalplane.adapters.openai import execute_tool_call
|
|
38
|
+
return execute_tool_call(client, "crystal_assemble", {"query": query, "max_tokens": max_tokens})
|
|
39
|
+
|
|
40
|
+
@tool
|
|
41
|
+
def crystal_crystallize(title: str, domain: str, raw_text: str, author_id: str = "agent:langchain") -> str:
|
|
42
|
+
"""Persist a new skill, trace, or memory into a durable SHA-256 microchain Shard."""
|
|
43
|
+
from crystalplane.adapters.openai import execute_tool_call
|
|
44
|
+
return execute_tool_call(client, "crystal_crystallize", {
|
|
45
|
+
"title": title,
|
|
46
|
+
"domain": domain,
|
|
47
|
+
"raw_text": raw_text,
|
|
48
|
+
"author_id": author_id
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
return [crystal_search, crystal_get_shard, crystal_assemble, crystal_crystallize]
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Crystalplane — OpenAI Function Calling & Swarm Adapter
|
|
3
|
+
Provides standard OpenAI JSON tool schemas and automatic tool call execution.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
import json
|
|
9
|
+
from typing import Any, Dict, List
|
|
10
|
+
|
|
11
|
+
from crystalplane.client import CrystalClient
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def get_openai_tools() -> List[Dict[str, Any]]:
|
|
15
|
+
"""Returns tool schemas compatible with `client.chat.completions.create(tools=...)`."""
|
|
16
|
+
return [
|
|
17
|
+
{
|
|
18
|
+
"type": "function",
|
|
19
|
+
"function": {
|
|
20
|
+
"name": "crystal_search",
|
|
21
|
+
"description": "Search the Crystalplane repository for authoritative skill and knowledge shards.",
|
|
22
|
+
"parameters": {
|
|
23
|
+
"type": "object",
|
|
24
|
+
"properties": {
|
|
25
|
+
"query": {
|
|
26
|
+
"type": "string",
|
|
27
|
+
"description": "Keywords or semantic terms to search for (e.g. 'GAAP revenue recognition' or 'dead-time insertion')"
|
|
28
|
+
},
|
|
29
|
+
"domain": {
|
|
30
|
+
"type": "string",
|
|
31
|
+
"description": "Optional lab domain filter (e.g. 'software', 'research', 'hardware', 'accounting')"
|
|
32
|
+
},
|
|
33
|
+
"limit": {
|
|
34
|
+
"type": "integer",
|
|
35
|
+
"description": "Maximum number of shards to return (default: 5)"
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"required": ["query"]
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
"type": "function",
|
|
44
|
+
"function": {
|
|
45
|
+
"name": "crystal_get_shard",
|
|
46
|
+
"description": "Retrieve the complete authoritative markdown content and metadata for a specific Shard by ID.",
|
|
47
|
+
"parameters": {
|
|
48
|
+
"type": "object",
|
|
49
|
+
"properties": {
|
|
50
|
+
"shard_id": {
|
|
51
|
+
"type": "string",
|
|
52
|
+
"description": "The canonical ID of the shard (e.g. 'sh_core_directive_mathematical_fidelity')"
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
"required": ["shard_id"]
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
"type": "function",
|
|
61
|
+
"function": {
|
|
62
|
+
"name": "crystal_assemble",
|
|
63
|
+
"description": "Assemble a Composite Skill Crystal within a strict token budget and retrieve the compiled prompt injection.",
|
|
64
|
+
"parameters": {
|
|
65
|
+
"type": "object",
|
|
66
|
+
"properties": {
|
|
67
|
+
"query": {
|
|
68
|
+
"type": "string",
|
|
69
|
+
"description": "Search query describing the domain skills needed"
|
|
70
|
+
},
|
|
71
|
+
"max_tokens": {
|
|
72
|
+
"type": "integer",
|
|
73
|
+
"description": "Maximum token budget (e.g. 2048)"
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
"required": ["query"]
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
"type": "function",
|
|
82
|
+
"function": {
|
|
83
|
+
"name": "crystal_crystallize",
|
|
84
|
+
"description": "Persist a newly discovered skill, execution trace, or episodic memory into a durable SHA-256 microchain Shard.",
|
|
85
|
+
"parameters": {
|
|
86
|
+
"type": "object",
|
|
87
|
+
"properties": {
|
|
88
|
+
"title": { "type": "string", "description": "Title of the knowledge or skill shard" },
|
|
89
|
+
"domain": { "type": "string", "description": "Domain (e.g. 'software', 'research')" },
|
|
90
|
+
"raw_text": { "type": "string", "description": "Markdown specification or documentation" },
|
|
91
|
+
"author_id": { "type": "string", "description": "Agent handle or identifier" },
|
|
92
|
+
"tags": { "type": "array", "items": { "type": "string" }, "description": "Optional search tags" }
|
|
93
|
+
},
|
|
94
|
+
"required": ["title", "domain", "raw_text", "author_id"]
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
]
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def execute_tool_call(client: CrystalClient, tool_name: str, arguments: str | Dict[str, Any]) -> str:
|
|
102
|
+
"""Dispatches an OpenAI tool call and returns stringified JSON result."""
|
|
103
|
+
if isinstance(arguments, str):
|
|
104
|
+
try:
|
|
105
|
+
args = json.loads(arguments)
|
|
106
|
+
except Exception:
|
|
107
|
+
args = {}
|
|
108
|
+
else:
|
|
109
|
+
args = arguments
|
|
110
|
+
|
|
111
|
+
if tool_name == "crystal_search":
|
|
112
|
+
shards = client.search(
|
|
113
|
+
query=args.get("query", ""),
|
|
114
|
+
domain=args.get("domain"),
|
|
115
|
+
limit=args.get("limit", 5)
|
|
116
|
+
)
|
|
117
|
+
return json.dumps([
|
|
118
|
+
{
|
|
119
|
+
"id": s.id,
|
|
120
|
+
"title": s.title,
|
|
121
|
+
"domain": s.domain,
|
|
122
|
+
"tokens": s.token_count,
|
|
123
|
+
"preview": s.plaintext[:300] + ("..." if len(s.plaintext) > 300 else "")
|
|
124
|
+
}
|
|
125
|
+
for s in shards
|
|
126
|
+
])
|
|
127
|
+
|
|
128
|
+
elif tool_name == "crystal_get_shard":
|
|
129
|
+
shard = client.get_shard(shard_id=args.get("shard_id", ""))
|
|
130
|
+
if not shard:
|
|
131
|
+
return json.dumps({"error": f"Shard '{args.get('shard_id')}' not found."})
|
|
132
|
+
return json.dumps(shard.to_dict())
|
|
133
|
+
|
|
134
|
+
elif tool_name == "crystal_assemble":
|
|
135
|
+
assembled = client.assemble(
|
|
136
|
+
query=args.get("query"),
|
|
137
|
+
max_tokens=args.get("max_tokens", 2048)
|
|
138
|
+
)
|
|
139
|
+
return json.dumps({
|
|
140
|
+
"title": assembled.title,
|
|
141
|
+
"crystalId": assembled.crystal_id,
|
|
142
|
+
"totalTokens": assembled.total_tokens,
|
|
143
|
+
"shardsCount": assembled.shards_count,
|
|
144
|
+
"promptInjection": assembled.prompt_injection
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
elif tool_name == "crystal_crystallize":
|
|
148
|
+
shard = client.crystallize(
|
|
149
|
+
title=args.get("title", "Untitled Shard"),
|
|
150
|
+
domain=args.get("domain", "software"),
|
|
151
|
+
raw_text=args.get("raw_text", ""),
|
|
152
|
+
author_id=args.get("author_id", "agent:openai"),
|
|
153
|
+
tags=args.get("tags")
|
|
154
|
+
)
|
|
155
|
+
return json.dumps({
|
|
156
|
+
"message": "Shard successfully crystallized and committed to blockchain.",
|
|
157
|
+
"shardId": shard.id,
|
|
158
|
+
"title": shard.title,
|
|
159
|
+
"tokens": shard.token_count
|
|
160
|
+
})
|
|
161
|
+
|
|
162
|
+
return json.dumps({"error": f"Unknown tool: {tool_name}"})
|