jarviscore-framework 0.3.0__py3-none-any.whl → 0.3.1__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.
- examples/cloud_deployment_example.py +3 -3
- examples/{listeneragent_cognitive_discovery_example.py → customagent_cognitive_discovery_example.py} +6 -6
- examples/fastapi_integration_example.py +4 -4
- jarviscore/__init__.py +8 -11
- jarviscore/cli/smoketest.py +1 -1
- jarviscore/core/mesh.py +9 -0
- jarviscore/data/examples/cloud_deployment_example.py +3 -3
- jarviscore/data/examples/custom_profile_decorator.py +134 -0
- jarviscore/data/examples/custom_profile_wrap.py +168 -0
- jarviscore/data/examples/{listeneragent_cognitive_discovery_example.py → customagent_cognitive_discovery_example.py} +6 -6
- jarviscore/data/examples/fastapi_integration_example.py +4 -4
- jarviscore/docs/API_REFERENCE.md +32 -45
- jarviscore/docs/CHANGELOG.md +42 -0
- jarviscore/docs/CONFIGURATION.md +1 -1
- jarviscore/docs/CUSTOMAGENT_GUIDE.md +246 -153
- jarviscore/docs/GETTING_STARTED.md +186 -329
- jarviscore/docs/TROUBLESHOOTING.md +1 -1
- jarviscore/docs/USER_GUIDE.md +8 -9
- jarviscore/integrations/fastapi.py +4 -4
- jarviscore/p2p/peer_client.py +29 -2
- jarviscore/profiles/__init__.py +2 -4
- jarviscore/profiles/customagent.py +295 -74
- {jarviscore_framework-0.3.0.dist-info → jarviscore_framework-0.3.1.dist-info}/METADATA +61 -46
- {jarviscore_framework-0.3.0.dist-info → jarviscore_framework-0.3.1.dist-info}/RECORD +30 -29
- tests/test_13_dx_improvements.py +37 -37
- tests/test_15_llm_cognitive_discovery.py +18 -18
- tests/test_16_unified_dx_flow.py +3 -3
- jarviscore/profiles/listeneragent.py +0 -292
- {jarviscore_framework-0.3.0.dist-info → jarviscore_framework-0.3.1.dist-info}/WHEEL +0 -0
- {jarviscore_framework-0.3.0.dist-info → jarviscore_framework-0.3.1.dist-info}/licenses/LICENSE +0 -0
- {jarviscore_framework-0.3.0.dist-info → jarviscore_framework-0.3.1.dist-info}/top_level.txt +0 -0
|
@@ -28,10 +28,10 @@ import sys
|
|
|
28
28
|
|
|
29
29
|
sys.path.insert(0, '.')
|
|
30
30
|
|
|
31
|
-
from jarviscore.profiles import
|
|
31
|
+
from jarviscore.profiles import CustomAgent
|
|
32
32
|
|
|
33
33
|
|
|
34
|
-
class StandaloneProcessor(
|
|
34
|
+
class StandaloneProcessor(CustomAgent):
|
|
35
35
|
"""
|
|
36
36
|
Example standalone agent that joins mesh independently.
|
|
37
37
|
|
|
@@ -143,7 +143,7 @@ async def main():
|
|
|
143
143
|
print("Listening for peer requests...")
|
|
144
144
|
print("Press Ctrl+C to stop.\n")
|
|
145
145
|
|
|
146
|
-
# Run agent (
|
|
146
|
+
# Run agent (CustomAgent's run() handles the message loop)
|
|
147
147
|
try:
|
|
148
148
|
await agent.run()
|
|
149
149
|
except asyncio.CancelledError:
|
examples/{listeneragent_cognitive_discovery_example.py → customagent_cognitive_discovery_example.py}
RENAMED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"""
|
|
2
|
-
|
|
2
|
+
CustomAgent + Cognitive Discovery Example
|
|
3
3
|
|
|
4
4
|
Demonstrates two v0.3.0 features:
|
|
5
5
|
|
|
6
|
-
1.
|
|
6
|
+
1. CustomAgent - Handler-based P2P agents (no run() loop needed)
|
|
7
7
|
- on_peer_request() handles incoming requests
|
|
8
8
|
- on_peer_notify() handles broadcast notifications
|
|
9
9
|
|
|
@@ -25,18 +25,18 @@ from pathlib import Path
|
|
|
25
25
|
sys.path.insert(0, str(Path(__file__).parent.parent))
|
|
26
26
|
|
|
27
27
|
from jarviscore import Mesh
|
|
28
|
-
from jarviscore.profiles import
|
|
28
|
+
from jarviscore.profiles import CustomAgent
|
|
29
29
|
|
|
30
30
|
|
|
31
31
|
# ═══════════════════════════════════════════════════════════════════════════════
|
|
32
32
|
# SPECIALIST AGENT - Responds to requests from other agents
|
|
33
33
|
# ═══════════════════════════════════════════════════════════════════════════════
|
|
34
34
|
|
|
35
|
-
class AnalystAgent(
|
|
35
|
+
class AnalystAgent(CustomAgent):
|
|
36
36
|
"""
|
|
37
37
|
Specialist agent that handles analysis requests.
|
|
38
38
|
|
|
39
|
-
Uses
|
|
39
|
+
Uses CustomAgent profile - just implement handlers, no run() loop needed.
|
|
40
40
|
"""
|
|
41
41
|
role = "analyst"
|
|
42
42
|
capabilities = ["data_analysis", "statistics", "insights"]
|
|
@@ -62,7 +62,7 @@ class AnalystAgent(ListenerAgent):
|
|
|
62
62
|
# COORDINATOR AGENT - Uses LLM with cognitive discovery
|
|
63
63
|
# ═══════════════════════════════════════════════════════════════════════════════
|
|
64
64
|
|
|
65
|
-
class CoordinatorAgent(
|
|
65
|
+
class CoordinatorAgent(CustomAgent):
|
|
66
66
|
"""
|
|
67
67
|
Coordinator agent that uses LLM with dynamic peer discovery.
|
|
68
68
|
|
|
@@ -5,7 +5,7 @@ Demonstrates JarvisLifespan for 3-line FastAPI integration with autonomous agent
|
|
|
5
5
|
|
|
6
6
|
Features shown:
|
|
7
7
|
1. JarvisLifespan - Automatic agent lifecycle management
|
|
8
|
-
2.
|
|
8
|
+
2. CustomAgent - API-first agents with on_peer_request handlers
|
|
9
9
|
3. Cognitive Discovery - get_cognitive_context() for LLM awareness
|
|
10
10
|
4. Autonomous Agents - Each agent has MESH as a TOOL, LLM decides when to delegate
|
|
11
11
|
|
|
@@ -45,14 +45,14 @@ except ImportError:
|
|
|
45
45
|
FASTAPI_AVAILABLE = False
|
|
46
46
|
print("FastAPI not installed. Run: pip install fastapi uvicorn")
|
|
47
47
|
|
|
48
|
-
from jarviscore.profiles import
|
|
48
|
+
from jarviscore.profiles import CustomAgent
|
|
49
49
|
|
|
50
50
|
|
|
51
51
|
# ═══════════════════════════════════════════════════════════════════════════════
|
|
52
52
|
# LLM-POWERED AGENT BASE - Each agent can discover and delegate
|
|
53
53
|
# ═══════════════════════════════════════════════════════════════════════════════
|
|
54
54
|
|
|
55
|
-
class LLMAgent(
|
|
55
|
+
class LLMAgent(CustomAgent):
|
|
56
56
|
"""
|
|
57
57
|
Base for LLM-powered agents that can discover and delegate to peers.
|
|
58
58
|
|
|
@@ -544,7 +544,7 @@ def main():
|
|
|
544
544
|
print("=" * 60)
|
|
545
545
|
print("\n - FastAPI Integration:")
|
|
546
546
|
print(" - JarvisLifespan for one-line integration")
|
|
547
|
-
print(" -
|
|
547
|
+
print(" - CustomAgent with on_peer_request handlers")
|
|
548
548
|
print(" - Cognitive discovery via get_cognitive_context()")
|
|
549
549
|
print("\n - Cloud Deployment:")
|
|
550
550
|
print(" - Each agent has MESH as a TOOL")
|
jarviscore/__init__.py
CHANGED
|
@@ -4,16 +4,15 @@ JarvisCore - P2P Distributed Agent Framework
|
|
|
4
4
|
A production-grade framework for building autonomous agent systems with:
|
|
5
5
|
- P2P coordination via SWIM protocol
|
|
6
6
|
- Workflow orchestration with dependencies
|
|
7
|
-
-
|
|
7
|
+
- Two agent profiles: AutoAgent and CustomAgent
|
|
8
8
|
|
|
9
9
|
Profiles:
|
|
10
|
-
AutoAgent
|
|
11
|
-
CustomAgent
|
|
12
|
-
ListenerAgent - API-first agents with background P2P (just implement handlers)
|
|
10
|
+
AutoAgent - LLM generates and executes code from prompts (autonomous mode)
|
|
11
|
+
CustomAgent - You provide handlers or execute_task() (p2p/distributed modes)
|
|
13
12
|
|
|
14
13
|
Modes:
|
|
15
14
|
autonomous - Workflow engine only (AutoAgent)
|
|
16
|
-
p2p - P2P coordinator only (CustomAgent
|
|
15
|
+
p2p - P2P coordinator only (CustomAgent with run() loop)
|
|
17
16
|
distributed - Both workflow + P2P (CustomAgent with execute_task())
|
|
18
17
|
|
|
19
18
|
Quick Start (AutoAgent - autonomous mode):
|
|
@@ -30,12 +29,12 @@ Quick Start (AutoAgent - autonomous mode):
|
|
|
30
29
|
await mesh.start()
|
|
31
30
|
results = await mesh.workflow("calc", [{"agent": "calculator", "task": "Calculate 10!"}])
|
|
32
31
|
|
|
33
|
-
Quick Start (
|
|
32
|
+
Quick Start (CustomAgent + FastAPI):
|
|
34
33
|
from fastapi import FastAPI
|
|
35
|
-
from jarviscore.profiles import
|
|
34
|
+
from jarviscore.profiles import CustomAgent
|
|
36
35
|
from jarviscore.integrations.fastapi import JarvisLifespan
|
|
37
36
|
|
|
38
|
-
class MyAgent(
|
|
37
|
+
class MyAgent(CustomAgent):
|
|
39
38
|
role = "processor"
|
|
40
39
|
capabilities = ["processing"]
|
|
41
40
|
|
|
@@ -61,7 +60,7 @@ Quick Start (CustomAgent - distributed mode):
|
|
|
61
60
|
results = await mesh.workflow("demo", [{"agent": "processor", "task": "hello"}])
|
|
62
61
|
"""
|
|
63
62
|
|
|
64
|
-
__version__ = "0.3.
|
|
63
|
+
__version__ = "0.3.1"
|
|
65
64
|
__author__ = "JarvisCore Contributors"
|
|
66
65
|
__license__ = "MIT"
|
|
67
66
|
|
|
@@ -73,7 +72,6 @@ from jarviscore.core.mesh import Mesh, MeshMode
|
|
|
73
72
|
# Execution profiles
|
|
74
73
|
from jarviscore.profiles.autoagent import AutoAgent
|
|
75
74
|
from jarviscore.profiles.customagent import CustomAgent
|
|
76
|
-
from jarviscore.profiles.listeneragent import ListenerAgent
|
|
77
75
|
|
|
78
76
|
# Custom Profile: Decorator, Wrapper, and Context
|
|
79
77
|
from jarviscore.adapter import jarvis_agent, wrap
|
|
@@ -99,7 +97,6 @@ __all__ = [
|
|
|
99
97
|
# Profiles
|
|
100
98
|
"AutoAgent",
|
|
101
99
|
"CustomAgent",
|
|
102
|
-
"ListenerAgent",
|
|
103
100
|
|
|
104
101
|
# Custom Profile (decorator and wrapper)
|
|
105
102
|
"jarvis_agent",
|
jarviscore/cli/smoketest.py
CHANGED
|
@@ -313,7 +313,7 @@ class SmokeTest:
|
|
|
313
313
|
print("\nJarvisCore is working correctly. Next steps:")
|
|
314
314
|
print(" 1. AutoAgent example: python examples/calculator_agent_example.py")
|
|
315
315
|
print(" 2. CustomAgent P2P: python examples/customagent_p2p_example.py")
|
|
316
|
-
print(" 3.
|
|
316
|
+
print(" 3. Cognitive Discovery: python examples/customagent_cognitive_discovery_example.py")
|
|
317
317
|
print(" 4. FastAPI (v0.3): python examples/fastapi_integration_example.py")
|
|
318
318
|
print(" 5. Cloud deploy (v0.3): python examples/cloud_deployment_example.py")
|
|
319
319
|
print("\nDocumentation:")
|
jarviscore/core/mesh.py
CHANGED
|
@@ -256,9 +256,18 @@ class Mesh:
|
|
|
256
256
|
await self._p2p_coordinator.start()
|
|
257
257
|
self._logger.info("✓ P2P coordinator started")
|
|
258
258
|
|
|
259
|
+
# Wait for mesh to stabilize before announcing
|
|
260
|
+
# Increased delay to ensure SWIM fully connects all nodes
|
|
261
|
+
await asyncio.sleep(5)
|
|
262
|
+
self._logger.info("Waited for mesh stabilization")
|
|
263
|
+
|
|
259
264
|
# Announce capabilities to network
|
|
260
265
|
await self._p2p_coordinator.announce_capabilities()
|
|
261
266
|
self._logger.info("✓ Capabilities announced to mesh")
|
|
267
|
+
|
|
268
|
+
# Request capabilities from existing peers (for late-joiners)
|
|
269
|
+
await self._p2p_coordinator.request_peer_capabilities()
|
|
270
|
+
self._logger.info("✓ Requested capabilities from existing peers")
|
|
262
271
|
|
|
263
272
|
# Inject PeerClients for p2p mode
|
|
264
273
|
if self.mode == MeshMode.P2P:
|
|
@@ -28,10 +28,10 @@ import sys
|
|
|
28
28
|
|
|
29
29
|
sys.path.insert(0, '.')
|
|
30
30
|
|
|
31
|
-
from jarviscore.profiles import
|
|
31
|
+
from jarviscore.profiles import CustomAgent
|
|
32
32
|
|
|
33
33
|
|
|
34
|
-
class StandaloneProcessor(
|
|
34
|
+
class StandaloneProcessor(CustomAgent):
|
|
35
35
|
"""
|
|
36
36
|
Example standalone agent that joins mesh independently.
|
|
37
37
|
|
|
@@ -143,7 +143,7 @@ async def main():
|
|
|
143
143
|
print("Listening for peer requests...")
|
|
144
144
|
print("Press Ctrl+C to stop.\n")
|
|
145
145
|
|
|
146
|
-
# Run agent (
|
|
146
|
+
# Run agent (CustomAgent's run() handles the message loop)
|
|
147
147
|
try:
|
|
148
148
|
await agent.run()
|
|
149
149
|
except asyncio.CancelledError:
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Custom Profile Example: Using @jarvis_agent Decorator
|
|
3
|
+
|
|
4
|
+
This example shows how to use the @jarvis_agent decorator to convert
|
|
5
|
+
any Python class into a JarvisCore agent without modifying the class.
|
|
6
|
+
|
|
7
|
+
Use Case: You have existing Python classes/agents and want JarvisCore
|
|
8
|
+
to handle orchestration (data handoff, dependencies, shared memory).
|
|
9
|
+
"""
|
|
10
|
+
import asyncio
|
|
11
|
+
from jarviscore import Mesh, jarvis_agent, JarvisContext
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
# Example 1: Simple decorator (no context needed)
|
|
15
|
+
@jarvis_agent(role="processor", capabilities=["data_processing"])
|
|
16
|
+
class DataProcessor:
|
|
17
|
+
"""Simple data processor - doubles input values."""
|
|
18
|
+
|
|
19
|
+
def run(self, data):
|
|
20
|
+
"""Process data by doubling values."""
|
|
21
|
+
if isinstance(data, list):
|
|
22
|
+
return {"processed": [x * 2 for x in data]}
|
|
23
|
+
return {"processed": data * 2}
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
# Example 2: Decorator with context access
|
|
27
|
+
@jarvis_agent(role="aggregator", capabilities=["aggregation"])
|
|
28
|
+
class Aggregator:
|
|
29
|
+
"""Aggregates results from previous steps using JarvisContext."""
|
|
30
|
+
|
|
31
|
+
def run(self, task, ctx: JarvisContext):
|
|
32
|
+
"""
|
|
33
|
+
Access previous step results via ctx.previous().
|
|
34
|
+
|
|
35
|
+
Args:
|
|
36
|
+
task: The task description
|
|
37
|
+
ctx: JarvisContext with memory and dependency access
|
|
38
|
+
"""
|
|
39
|
+
# Get output from a specific previous step
|
|
40
|
+
processed = ctx.previous("step1")
|
|
41
|
+
|
|
42
|
+
if processed:
|
|
43
|
+
data = processed.get("processed", [])
|
|
44
|
+
return {
|
|
45
|
+
"sum": sum(data) if isinstance(data, list) else data,
|
|
46
|
+
"count": len(data) if isinstance(data, list) else 1,
|
|
47
|
+
"source_step": "step1"
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return {"error": "No previous data found"}
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
# Example 3: Decorator with custom execute method
|
|
54
|
+
@jarvis_agent(role="validator", capabilities=["validation"], execute_method="validate")
|
|
55
|
+
class DataValidator:
|
|
56
|
+
"""Validates data using a custom method name."""
|
|
57
|
+
|
|
58
|
+
def validate(self, data):
|
|
59
|
+
"""Custom execute method - validates input data."""
|
|
60
|
+
if isinstance(data, list):
|
|
61
|
+
return {
|
|
62
|
+
"valid": all(isinstance(x, (int, float)) for x in data),
|
|
63
|
+
"count": len(data),
|
|
64
|
+
"type": "list"
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
"valid": isinstance(data, (int, float)),
|
|
68
|
+
"type": type(data).__name__
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
async def main():
|
|
73
|
+
"""Run a multi-step workflow with custom profile agents."""
|
|
74
|
+
print("=" * 60)
|
|
75
|
+
print(" Custom Profile Example: @jarvis_agent Decorator")
|
|
76
|
+
print("=" * 60)
|
|
77
|
+
|
|
78
|
+
# Create mesh in autonomous mode
|
|
79
|
+
mesh = Mesh(mode="autonomous")
|
|
80
|
+
|
|
81
|
+
# Add our decorated agents
|
|
82
|
+
mesh.add(DataProcessor)
|
|
83
|
+
mesh.add(Aggregator)
|
|
84
|
+
mesh.add(DataValidator)
|
|
85
|
+
|
|
86
|
+
# Start the mesh
|
|
87
|
+
await mesh.start()
|
|
88
|
+
|
|
89
|
+
try:
|
|
90
|
+
# Execute a multi-step workflow
|
|
91
|
+
print("\nExecuting workflow with 3 steps...\n")
|
|
92
|
+
|
|
93
|
+
results = await mesh.workflow("custom-profile-demo", [
|
|
94
|
+
{
|
|
95
|
+
"id": "step1",
|
|
96
|
+
"agent": "processor",
|
|
97
|
+
"task": "Process input data",
|
|
98
|
+
"params": {"data": [1, 2, 3, 4, 5]}
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
"id": "step2",
|
|
102
|
+
"agent": "aggregator",
|
|
103
|
+
"task": "Aggregate processed results",
|
|
104
|
+
"depends_on": ["step1"] # Wait for step1
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
"id": "step3",
|
|
108
|
+
"agent": "validator",
|
|
109
|
+
"task": "Validate original data",
|
|
110
|
+
"params": {"data": [1, 2, 3, 4, 5]}
|
|
111
|
+
}
|
|
112
|
+
])
|
|
113
|
+
|
|
114
|
+
# Print results
|
|
115
|
+
print("Results:")
|
|
116
|
+
print("-" * 40)
|
|
117
|
+
|
|
118
|
+
for i, result in enumerate(results):
|
|
119
|
+
step_name = ["Processor", "Aggregator", "Validator"][i]
|
|
120
|
+
print(f"\n{step_name} (step{i+1}):")
|
|
121
|
+
print(f" Status: {result.get('status')}")
|
|
122
|
+
print(f" Output: {result.get('output')}")
|
|
123
|
+
|
|
124
|
+
print("\n" + "=" * 60)
|
|
125
|
+
print(" Workflow completed successfully!")
|
|
126
|
+
print("=" * 60)
|
|
127
|
+
|
|
128
|
+
finally:
|
|
129
|
+
# Stop the mesh
|
|
130
|
+
await mesh.stop()
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
if __name__ == "__main__":
|
|
134
|
+
asyncio.run(main())
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Custom Profile Example: Using wrap() Function
|
|
3
|
+
|
|
4
|
+
This example shows how to use the wrap() function to convert
|
|
5
|
+
an existing instance into a JarvisCore agent.
|
|
6
|
+
|
|
7
|
+
Use Case: You have an already-instantiated object (like a LangChain
|
|
8
|
+
agent, CrewAI agent, or any configured instance) and want to use it
|
|
9
|
+
with JarvisCore orchestration.
|
|
10
|
+
"""
|
|
11
|
+
import asyncio
|
|
12
|
+
from jarviscore import Mesh, wrap, JarvisContext
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
# Simulate an existing "LangChain-like" agent
|
|
16
|
+
class ExternalLLMAgent:
|
|
17
|
+
"""
|
|
18
|
+
Simulates an external LLM agent (like LangChain).
|
|
19
|
+
In real usage, this would be your actual LangChain/CrewAI agent.
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
def __init__(self, model_name: str, temperature: float = 0.7):
|
|
23
|
+
self.model_name = model_name
|
|
24
|
+
self.temperature = temperature
|
|
25
|
+
print(f" Initialized ExternalLLMAgent with {model_name}")
|
|
26
|
+
|
|
27
|
+
def invoke(self, query: str) -> dict:
|
|
28
|
+
"""LangChain-style invoke method."""
|
|
29
|
+
# Simulate LLM response
|
|
30
|
+
return {
|
|
31
|
+
"answer": f"Response to '{query}' from {self.model_name}",
|
|
32
|
+
"model": self.model_name,
|
|
33
|
+
"tokens_used": len(query.split()) * 10
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
# Simulate a data processing service
|
|
38
|
+
class DataService:
|
|
39
|
+
"""Simulates an external data processing service."""
|
|
40
|
+
|
|
41
|
+
def __init__(self, api_url: str):
|
|
42
|
+
self.api_url = api_url
|
|
43
|
+
print(f" Initialized DataService with {api_url}")
|
|
44
|
+
|
|
45
|
+
def run(self, data):
|
|
46
|
+
"""Process data through the service."""
|
|
47
|
+
if isinstance(data, list):
|
|
48
|
+
return {
|
|
49
|
+
"transformed": [x ** 2 for x in data],
|
|
50
|
+
"source": self.api_url
|
|
51
|
+
}
|
|
52
|
+
return {"transformed": data ** 2, "source": self.api_url}
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
# Simulate an agent that needs context
|
|
56
|
+
class ContextAwareProcessor:
|
|
57
|
+
"""Agent that uses JarvisContext to access previous results."""
|
|
58
|
+
|
|
59
|
+
def run(self, task, ctx: JarvisContext):
|
|
60
|
+
"""Process with context access."""
|
|
61
|
+
# Get all previous results
|
|
62
|
+
all_previous = ctx.all_previous()
|
|
63
|
+
|
|
64
|
+
summary = {
|
|
65
|
+
"task": task,
|
|
66
|
+
"previous_steps": list(all_previous.keys()),
|
|
67
|
+
"combined_data": {}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
for step_id, output in all_previous.items():
|
|
71
|
+
if isinstance(output, dict):
|
|
72
|
+
summary["combined_data"][step_id] = output
|
|
73
|
+
|
|
74
|
+
return summary
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
async def main():
|
|
78
|
+
"""Demonstrate wrapping existing instances."""
|
|
79
|
+
print("=" * 60)
|
|
80
|
+
print(" Custom Profile Example: wrap() Function")
|
|
81
|
+
print("=" * 60)
|
|
82
|
+
|
|
83
|
+
# Create instances of "external" agents
|
|
84
|
+
print("\nCreating external agent instances...")
|
|
85
|
+
llm_agent = ExternalLLMAgent(model_name="gpt-4-turbo", temperature=0.3)
|
|
86
|
+
data_service = DataService(api_url="https://api.example.com/process")
|
|
87
|
+
context_processor = ContextAwareProcessor()
|
|
88
|
+
|
|
89
|
+
# Wrap them for JarvisCore
|
|
90
|
+
print("\nWrapping instances for JarvisCore...")
|
|
91
|
+
|
|
92
|
+
wrapped_llm = wrap(
|
|
93
|
+
llm_agent,
|
|
94
|
+
role="llm_assistant",
|
|
95
|
+
capabilities=["chat", "qa"],
|
|
96
|
+
execute_method="invoke" # LangChain uses "invoke"
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
wrapped_data = wrap(
|
|
100
|
+
data_service,
|
|
101
|
+
role="data_processor",
|
|
102
|
+
capabilities=["data_processing", "transformation"]
|
|
103
|
+
# execute_method auto-detected as "run"
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
wrapped_context = wrap(
|
|
107
|
+
context_processor,
|
|
108
|
+
role="context_aggregator",
|
|
109
|
+
capabilities=["aggregation", "summary"]
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
# Create mesh and add wrapped agents
|
|
113
|
+
mesh = Mesh(mode="autonomous")
|
|
114
|
+
mesh.add(wrapped_llm)
|
|
115
|
+
mesh.add(wrapped_data)
|
|
116
|
+
mesh.add(wrapped_context)
|
|
117
|
+
|
|
118
|
+
await mesh.start()
|
|
119
|
+
|
|
120
|
+
try:
|
|
121
|
+
print("\nExecuting workflow with wrapped agents...\n")
|
|
122
|
+
|
|
123
|
+
results = await mesh.workflow("wrap-demo", [
|
|
124
|
+
{
|
|
125
|
+
"id": "llm_step",
|
|
126
|
+
"agent": "llm_assistant",
|
|
127
|
+
"task": "What is the capital of France?",
|
|
128
|
+
"params": {"query": "What is the capital of France?"}
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
"id": "data_step",
|
|
132
|
+
"agent": "data_processor",
|
|
133
|
+
"task": "Transform numbers",
|
|
134
|
+
"params": {"data": [1, 2, 3, 4, 5]}
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
"id": "summary_step",
|
|
138
|
+
"agent": "context_aggregator",
|
|
139
|
+
"task": "Summarize all results",
|
|
140
|
+
"depends_on": ["llm_step", "data_step"]
|
|
141
|
+
}
|
|
142
|
+
])
|
|
143
|
+
|
|
144
|
+
# Print results
|
|
145
|
+
print("Results:")
|
|
146
|
+
print("-" * 40)
|
|
147
|
+
|
|
148
|
+
step_names = ["LLM Assistant", "Data Processor", "Context Aggregator"]
|
|
149
|
+
for i, result in enumerate(results):
|
|
150
|
+
print(f"\n{step_names[i]}:")
|
|
151
|
+
print(f" Status: {result.get('status')}")
|
|
152
|
+
output = result.get('output', {})
|
|
153
|
+
if isinstance(output, dict):
|
|
154
|
+
for key, value in output.items():
|
|
155
|
+
print(f" {key}: {value}")
|
|
156
|
+
else:
|
|
157
|
+
print(f" Output: {output}")
|
|
158
|
+
|
|
159
|
+
print("\n" + "=" * 60)
|
|
160
|
+
print(" Workflow with wrapped instances completed!")
|
|
161
|
+
print("=" * 60)
|
|
162
|
+
|
|
163
|
+
finally:
|
|
164
|
+
await mesh.stop()
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
if __name__ == "__main__":
|
|
168
|
+
asyncio.run(main())
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"""
|
|
2
|
-
|
|
2
|
+
CustomAgent + Cognitive Discovery Example
|
|
3
3
|
|
|
4
4
|
Demonstrates two v0.3.0 features:
|
|
5
5
|
|
|
6
|
-
1.
|
|
6
|
+
1. CustomAgent - Handler-based P2P agents (no run() loop needed)
|
|
7
7
|
- on_peer_request() handles incoming requests
|
|
8
8
|
- on_peer_notify() handles broadcast notifications
|
|
9
9
|
|
|
@@ -25,18 +25,18 @@ from pathlib import Path
|
|
|
25
25
|
sys.path.insert(0, str(Path(__file__).parent.parent))
|
|
26
26
|
|
|
27
27
|
from jarviscore import Mesh
|
|
28
|
-
from jarviscore.profiles import
|
|
28
|
+
from jarviscore.profiles import CustomAgent
|
|
29
29
|
|
|
30
30
|
|
|
31
31
|
# ═══════════════════════════════════════════════════════════════════════════════
|
|
32
32
|
# SPECIALIST AGENT - Responds to requests from other agents
|
|
33
33
|
# ═══════════════════════════════════════════════════════════════════════════════
|
|
34
34
|
|
|
35
|
-
class AnalystAgent(
|
|
35
|
+
class AnalystAgent(CustomAgent):
|
|
36
36
|
"""
|
|
37
37
|
Specialist agent that handles analysis requests.
|
|
38
38
|
|
|
39
|
-
Uses
|
|
39
|
+
Uses CustomAgent profile - just implement handlers, no run() loop needed.
|
|
40
40
|
"""
|
|
41
41
|
role = "analyst"
|
|
42
42
|
capabilities = ["data_analysis", "statistics", "insights"]
|
|
@@ -62,7 +62,7 @@ class AnalystAgent(ListenerAgent):
|
|
|
62
62
|
# COORDINATOR AGENT - Uses LLM with cognitive discovery
|
|
63
63
|
# ═══════════════════════════════════════════════════════════════════════════════
|
|
64
64
|
|
|
65
|
-
class CoordinatorAgent(
|
|
65
|
+
class CoordinatorAgent(CustomAgent):
|
|
66
66
|
"""
|
|
67
67
|
Coordinator agent that uses LLM with dynamic peer discovery.
|
|
68
68
|
|
|
@@ -5,7 +5,7 @@ Demonstrates JarvisLifespan for 3-line FastAPI integration with autonomous agent
|
|
|
5
5
|
|
|
6
6
|
Features shown:
|
|
7
7
|
1. JarvisLifespan - Automatic agent lifecycle management
|
|
8
|
-
2.
|
|
8
|
+
2. CustomAgent - API-first agents with on_peer_request handlers
|
|
9
9
|
3. Cognitive Discovery - get_cognitive_context() for LLM awareness
|
|
10
10
|
4. Autonomous Agents - Each agent has MESH as a TOOL, LLM decides when to delegate
|
|
11
11
|
|
|
@@ -45,14 +45,14 @@ except ImportError:
|
|
|
45
45
|
FASTAPI_AVAILABLE = False
|
|
46
46
|
print("FastAPI not installed. Run: pip install fastapi uvicorn")
|
|
47
47
|
|
|
48
|
-
from jarviscore.profiles import
|
|
48
|
+
from jarviscore.profiles import CustomAgent
|
|
49
49
|
|
|
50
50
|
|
|
51
51
|
# ═══════════════════════════════════════════════════════════════════════════════
|
|
52
52
|
# LLM-POWERED AGENT BASE - Each agent can discover and delegate
|
|
53
53
|
# ═══════════════════════════════════════════════════════════════════════════════
|
|
54
54
|
|
|
55
|
-
class LLMAgent(
|
|
55
|
+
class LLMAgent(CustomAgent):
|
|
56
56
|
"""
|
|
57
57
|
Base for LLM-powered agents that can discover and delegate to peers.
|
|
58
58
|
|
|
@@ -544,7 +544,7 @@ def main():
|
|
|
544
544
|
print("=" * 60)
|
|
545
545
|
print("\n - FastAPI Integration:")
|
|
546
546
|
print(" - JarvisLifespan for one-line integration")
|
|
547
|
-
print(" -
|
|
547
|
+
print(" - CustomAgent with on_peer_request handlers")
|
|
548
548
|
print(" - Cognitive discovery via get_cognitive_context()")
|
|
549
549
|
print("\n - Cloud Deployment:")
|
|
550
550
|
print(" - Each agent has MESH as a TOOL")
|