jarviscore-framework 0.2.1__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.
Files changed (37) hide show
  1. examples/cloud_deployment_example.py +162 -0
  2. examples/customagent_cognitive_discovery_example.py +343 -0
  3. examples/fastapi_integration_example.py +570 -0
  4. jarviscore/__init__.py +19 -5
  5. jarviscore/cli/smoketest.py +8 -4
  6. jarviscore/core/agent.py +227 -0
  7. jarviscore/core/mesh.py +9 -0
  8. jarviscore/data/examples/cloud_deployment_example.py +162 -0
  9. jarviscore/data/examples/custom_profile_decorator.py +134 -0
  10. jarviscore/data/examples/custom_profile_wrap.py +168 -0
  11. jarviscore/data/examples/customagent_cognitive_discovery_example.py +343 -0
  12. jarviscore/data/examples/fastapi_integration_example.py +570 -0
  13. jarviscore/docs/API_REFERENCE.md +283 -3
  14. jarviscore/docs/CHANGELOG.md +139 -0
  15. jarviscore/docs/CONFIGURATION.md +1 -1
  16. jarviscore/docs/CUSTOMAGENT_GUIDE.md +997 -85
  17. jarviscore/docs/GETTING_STARTED.md +228 -267
  18. jarviscore/docs/TROUBLESHOOTING.md +1 -1
  19. jarviscore/docs/USER_GUIDE.md +153 -8
  20. jarviscore/integrations/__init__.py +16 -0
  21. jarviscore/integrations/fastapi.py +247 -0
  22. jarviscore/p2p/broadcaster.py +10 -3
  23. jarviscore/p2p/coordinator.py +310 -14
  24. jarviscore/p2p/keepalive.py +45 -23
  25. jarviscore/p2p/peer_client.py +311 -12
  26. jarviscore/p2p/swim_manager.py +9 -4
  27. jarviscore/profiles/__init__.py +7 -1
  28. jarviscore/profiles/customagent.py +295 -74
  29. {jarviscore_framework-0.2.1.dist-info → jarviscore_framework-0.3.1.dist-info}/METADATA +66 -18
  30. {jarviscore_framework-0.2.1.dist-info → jarviscore_framework-0.3.1.dist-info}/RECORD +37 -22
  31. {jarviscore_framework-0.2.1.dist-info → jarviscore_framework-0.3.1.dist-info}/WHEEL +1 -1
  32. tests/test_13_dx_improvements.py +554 -0
  33. tests/test_14_cloud_deployment.py +403 -0
  34. tests/test_15_llm_cognitive_discovery.py +684 -0
  35. tests/test_16_unified_dx_flow.py +947 -0
  36. {jarviscore_framework-0.2.1.dist-info → jarviscore_framework-0.3.1.dist-info}/licenses/LICENSE +0 -0
  37. {jarviscore_framework-0.2.1.dist-info → jarviscore_framework-0.3.1.dist-info}/top_level.txt +0 -0
@@ -14,7 +14,13 @@ Complete API documentation for JarvisCore framework components.
14
14
  - [AutoAgent](#autoagent)
15
15
  - [Custom Profile](#custom-profile)
16
16
  - [CustomAgent](#customagent)
17
- 3. [Execution Components](#execution-components)
17
+ 3. [P2P Communication (v0.3.0)](#p2p-communication-v030)
18
+ - [PeerClient](#peerclient)
19
+ - [IncomingMessage](#incomingmessage)
20
+ - [Cognitive Discovery](#cognitive-discovery)
21
+ 4. [Integrations (v0.3.0)](#integrations-v030)
22
+ - [JarvisLifespan](#jarvislifespan)
23
+ 5. [Execution Components](#execution-components)
18
24
  - [CodeGenerator](#codegenerator)
19
25
  - [SandboxExecutor](#sandboxexecutor)
20
26
  - [AutoRepair](#autorepair)
@@ -557,6 +563,280 @@ See [CustomAgent Guide](CUSTOMAGENT_GUIDE.md) for P2P and distributed mode detai
557
563
 
558
564
  ---
559
565
 
566
+ #### P2P Message Handlers
567
+
568
+ CustomAgent includes built-in P2P message handlers:
569
+
570
+ #### `async on_peer_request(msg) -> dict`
571
+
572
+ Handle incoming request messages. Return value is sent back to requester.
573
+
574
+ ```python
575
+ async def on_peer_request(self, msg):
576
+ query = msg.data.get("question", "")
577
+ result = self.process(query)
578
+ return {"response": result, "status": "success"}
579
+ ```
580
+
581
+ **Parameters:**
582
+ - `msg` (IncomingMessage): Incoming message with `data`, `sender`, `correlation_id`
583
+
584
+ **Returns:** dict - Response sent back to requester (if `auto_respond=True`)
585
+
586
+ ---
587
+
588
+ #### `async on_peer_notify(msg) -> None`
589
+
590
+ Handle broadcast notifications. No return value needed.
591
+
592
+ ```python
593
+ async def on_peer_notify(self, msg):
594
+ event_type = msg.data.get("type")
595
+ if event_type == "status_update":
596
+ self.handle_status(msg.data)
597
+ ```
598
+
599
+ **Parameters:**
600
+ - `msg` (IncomingMessage): Incoming notification message
601
+
602
+ **Returns:** None
603
+
604
+ ---
605
+
606
+ #### `async on_error(error, msg) -> None`
607
+
608
+ Handle errors during message processing.
609
+
610
+ ```python
611
+ async def on_error(self, error, msg):
612
+ self._logger.error(f"Error processing message: {error}")
613
+ ```
614
+
615
+ **Parameters:**
616
+ - `error` (Exception): The exception that occurred
617
+ - `msg` (IncomingMessage, optional): The message being processed
618
+
619
+ ---
620
+
621
+ #### Configuration Attributes
622
+
623
+ - `listen_timeout` (float): Seconds to wait for messages in run loop (default: 1.0)
624
+ - `auto_respond` (bool): Automatically send on_peer_request return value (default: True)
625
+
626
+ ---
627
+
628
+ #### Self-Registration Methods
629
+
630
+ #### `async join_mesh(seed_nodes, advertise_endpoint=None)`
631
+
632
+ Join an existing mesh without central orchestrator.
633
+
634
+ ```python
635
+ await agent.join_mesh(
636
+ seed_nodes="10.0.0.1:7950,10.0.0.2:7950",
637
+ advertise_endpoint="my-pod:7950"
638
+ )
639
+ ```
640
+
641
+ **Parameters:**
642
+ - `seed_nodes` (str): Comma-separated list of seed node addresses
643
+ - `advertise_endpoint` (str, optional): Address for other nodes to reach this agent
644
+
645
+ ---
646
+
647
+ #### `async leave_mesh()`
648
+
649
+ Gracefully leave the mesh network.
650
+
651
+ ```python
652
+ await agent.leave_mesh()
653
+ ```
654
+
655
+ ---
656
+
657
+ ## P2P Communication (v0.3.0)
658
+
659
+ ### PeerClient
660
+
661
+ Client for peer-to-peer communication, available as `self.peers` on agents.
662
+
663
+ #### Class: `PeerClient`
664
+
665
+ **Methods:**
666
+
667
+ #### `get_cognitive_context() -> str`
668
+
669
+ Generate LLM-ready text describing available peers.
670
+
671
+ ```python
672
+ if self.peers:
673
+ context = self.peers.get_cognitive_context()
674
+ # Returns:
675
+ # "Available Peers:
676
+ # - analyst (capabilities: analysis, data_interpretation)
677
+ # Use ask_peer with role="analyst" for analysis tasks
678
+ # - researcher (capabilities: research, web_search)
679
+ # Use ask_peer with role="researcher" for research tasks"
680
+ ```
681
+
682
+ **Returns:** str - Human-readable peer descriptions for LLM prompts
683
+
684
+ ---
685
+
686
+ #### `list() -> List[PeerInfo]`
687
+
688
+ Get list of connected peers.
689
+
690
+ ```python
691
+ peers = self.peers.list()
692
+ for peer in peers:
693
+ print(f"{peer.role}: {peer.capabilities}")
694
+ ```
695
+
696
+ **Returns:** List of PeerInfo objects
697
+
698
+ ---
699
+
700
+ #### `as_tool() -> PeerTool`
701
+
702
+ Get peer tools for LLM tool use.
703
+
704
+ ```python
705
+ tools = self.peers.as_tool()
706
+ result = await tools.execute("ask_peer", {"role": "analyst", "question": "..."})
707
+ ```
708
+
709
+ **Available Tools:**
710
+ - `ask_peer` - Send request and wait for response
711
+ - `broadcast` - Send notification to all peers
712
+ - `list_peers` - List available peers
713
+
714
+ ---
715
+
716
+ #### `async receive(timeout) -> IncomingMessage`
717
+
718
+ Receive next message (for CustomAgent manual loops).
719
+
720
+ ```python
721
+ msg = await self.peers.receive(timeout=0.5)
722
+ if msg and msg.is_request:
723
+ await self.peers.respond(msg, {"result": "..."})
724
+ ```
725
+
726
+ ---
727
+
728
+ #### `async respond(msg, data) -> None`
729
+
730
+ Respond to a request message.
731
+
732
+ ```python
733
+ await self.peers.respond(msg, {"status": "success", "result": data})
734
+ ```
735
+
736
+ ---
737
+
738
+ ### IncomingMessage
739
+
740
+ Message received from a peer.
741
+
742
+ #### Class: `IncomingMessage`
743
+
744
+ **Attributes:**
745
+ - `data` (dict): Message payload
746
+ - `sender_role` (str): Role of sending agent
747
+ - `sender_id` (str): ID of sending agent
748
+ - `is_request` (bool): True if this is a request expecting response
749
+ - `is_notify` (bool): True if this is a notification
750
+
751
+ ```python
752
+ async def on_peer_request(self, msg):
753
+ print(f"From: {msg.sender_role}")
754
+ print(f"Data: {msg.data}")
755
+ return {"received": True}
756
+ ```
757
+
758
+ ---
759
+
760
+ ### Cognitive Discovery
761
+
762
+ Dynamic peer awareness for LLM prompts.
763
+
764
+ **Pattern:**
765
+
766
+ ```python
767
+ class MyAgent(CustomAgent):
768
+ def get_system_prompt(self) -> str:
769
+ base = "You are a helpful assistant."
770
+
771
+ # Dynamically add peer context
772
+ if self.peers:
773
+ peer_context = self.peers.get_cognitive_context()
774
+ return f"{base}\n\n{peer_context}"
775
+
776
+ return base
777
+ ```
778
+
779
+ **Benefits:**
780
+ - No hardcoded agent names in prompts
781
+ - Automatically updates when peers join/leave
782
+ - LLM always knows current capabilities
783
+
784
+ ---
785
+
786
+ ## Integrations (v0.3.0)
787
+
788
+ ### JarvisLifespan
789
+
790
+ FastAPI lifespan context manager for automatic agent lifecycle management.
791
+
792
+ #### Class: `JarvisLifespan`
793
+
794
+ ```python
795
+ from jarviscore.integrations.fastapi import JarvisLifespan
796
+
797
+ app = FastAPI(lifespan=JarvisLifespan(agent, mode="p2p"))
798
+ ```
799
+
800
+ **Parameters:**
801
+ - `agent`: CustomAgent instance (or list of agents)
802
+ - `mode` (str): "p2p" or "distributed"
803
+ - `bind_port` (int, optional): P2P port (default: 7950)
804
+ - `seed_nodes` (str, optional): Comma-separated seed node addresses
805
+
806
+ **Example:**
807
+
808
+ ```python
809
+ from fastapi import FastAPI
810
+ from jarviscore.profiles import CustomAgent
811
+ from jarviscore.integrations.fastapi import JarvisLifespan
812
+
813
+
814
+ class ProcessorAgent(CustomAgent):
815
+ role = "processor"
816
+ capabilities = ["processing"]
817
+
818
+ async def on_peer_request(self, msg):
819
+ return {"result": "processed"}
820
+
821
+
822
+ agent = ProcessorAgent()
823
+ app = FastAPI(lifespan=JarvisLifespan(agent, mode="p2p", bind_port=7950))
824
+
825
+
826
+ @app.post("/process")
827
+ async def process(data: dict):
828
+ # Agent is already running and connected to mesh
829
+ return {"status": "ok"}
830
+ ```
831
+
832
+ **Handles:**
833
+ - Agent setup and teardown
834
+ - Mesh initialization
835
+ - Background run loop (runs agent.run())
836
+ - Graceful shutdown
837
+
838
+ ---
839
+
560
840
  ## Execution Components
561
841
 
562
842
  ### CodeGenerator
@@ -1140,6 +1420,6 @@ async def execute_task(self, task: Dict[str, Any]) -> Dict[str, Any]:
1140
1420
 
1141
1421
  ## Version
1142
1422
 
1143
- API Reference for JarvisCore v0.2.1
1423
+ API Reference for JarvisCore v0.3.1
1144
1424
 
1145
- Last Updated: 2026-01-23
1425
+ Last Updated: 2026-01-29
@@ -0,0 +1,139 @@
1
+ # Changelog
2
+
3
+ All notable changes to JarvisCore Framework will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ---
9
+
10
+ ## [0.3.1] - 2026-02-02
11
+
12
+ ### Breaking Changes
13
+
14
+ #### ListenerAgent Removed
15
+ - **ListenerAgent has been merged into CustomAgent**
16
+ - Migration is simple - just change the import:
17
+ ```python
18
+ # Before
19
+ from jarviscore.profiles import ListenerAgent
20
+ class MyAgent(ListenerAgent): ...
21
+
22
+ # After
23
+ from jarviscore.profiles import CustomAgent
24
+ class MyAgent(CustomAgent): ...
25
+ ```
26
+ - All handler methods work exactly the same way
27
+ - No other code changes required
28
+
29
+ ### Changed
30
+
31
+ #### CustomAgent Now Includes P2P Handlers
32
+ - `on_peer_request(msg)` - Handle incoming requests (return value sent as response)
33
+ - `on_peer_notify(msg)` - Handle fire-and-forget notifications
34
+ - `on_error(error, msg)` - Handle errors during message processing
35
+ - `run()` - Built-in listener loop (no need to write your own)
36
+ - Configuration: `listen_timeout`, `auto_respond`
37
+
38
+ #### Simplified Profile Architecture
39
+ | Before (v0.3.0) | After (v0.3.1) |
40
+ |-----------------|----------------|
41
+ | AutoAgent + CustomAgent + ListenerAgent | AutoAgent + CustomAgent |
42
+ | "Which profile do I use?" confusion | Clear: AutoAgent (LLM) or CustomAgent (your code) |
43
+
44
+ ### Documentation
45
+ - README.md updated with unified CustomAgent examples
46
+ - GETTING_STARTED.md rewritten with framework integration patterns
47
+ - CUSTOMAGENT_GUIDE.md updated (ListenerAgent sections removed)
48
+ - Added async-first framework guidance (FastAPI, aiohttp, Flask patterns)
49
+
50
+ ---
51
+
52
+ ## [0.3.0] - 2026-01-29
53
+
54
+ ### Added
55
+
56
+ #### ListenerAgent Profile
57
+ - New `ListenerAgent` class for handler-based P2P communication
58
+ - `on_peer_request(msg)` handler for incoming requests
59
+ - `on_peer_notify(msg)` handler for broadcast notifications
60
+ - No more manual `run()` loops required for simple P2P agents
61
+
62
+ #### FastAPI Integration
63
+ - `JarvisLifespan` context manager for 3-line FastAPI integration
64
+ - Automatic agent lifecycle management (setup, run, teardown)
65
+ - Support for both `p2p` and `distributed` modes
66
+ - Import: `from jarviscore.integrations.fastapi import JarvisLifespan`
67
+
68
+ #### Cognitive Discovery
69
+ - `peers.get_cognitive_context()` generates LLM-ready peer descriptions
70
+ - Dynamic peer awareness - no more hardcoded agent names in prompts
71
+ - Auto-updates when peers join or leave the mesh
72
+
73
+ #### Cloud Deployment
74
+ - `agent.join_mesh(seed_nodes)` for self-registration without central orchestrator
75
+ - `agent.leave_mesh()` for graceful departure
76
+ - `agent.serve_forever()` for container deployments
77
+ - `RemoteAgentProxy` for automatic cross-node agent visibility
78
+ - Environment variable support:
79
+ - `JARVISCORE_SEED_NODES` - comma-separated seed node addresses
80
+ - `JARVISCORE_MESH_ENDPOINT` - advertised endpoint for this agent
81
+ - `JARVISCORE_BIND_PORT` - P2P port
82
+
83
+ ### Changed
84
+
85
+ - Documentation restructured with before/after comparisons
86
+ - CUSTOMAGENT_GUIDE.md expanded with v0.3.0 features
87
+ - API_REFERENCE.md updated with new classes and methods
88
+
89
+ ### Developer Experience
90
+
91
+ | Before (v0.2.x) | After (v0.3.0) |
92
+ |-----------------|----------------|
93
+ | Manual `run()` loops with `receive()`/`respond()` | `ListenerAgent` with `on_peer_request()` handlers |
94
+ | ~100 lines for FastAPI integration | 3 lines with `JarvisLifespan` |
95
+ | Hardcoded peer names in LLM prompts | Dynamic `get_cognitive_context()` |
96
+ | Central orchestrator required | Self-registration with `join_mesh()` |
97
+
98
+ ---
99
+
100
+ ## [0.2.1] - 2026-01-23
101
+
102
+ ### Fixed
103
+ - P2P message routing stability improvements
104
+ - Workflow engine dependency resolution edge cases
105
+
106
+ ---
107
+
108
+ ## [0.2.0] - 2026-01-15
109
+
110
+ ### Added
111
+ - CustomAgent profile for integrating existing agent code
112
+ - P2P mode for direct agent-to-agent communication
113
+ - Distributed mode combining workflow engine + P2P
114
+ - `@jarvis_agent` decorator for wrapping existing classes
115
+ - `wrap()` function for wrapping existing instances
116
+ - `JarvisContext` for workflow context access
117
+ - Peer tools: `ask_peer`, `broadcast`, `list_peers`
118
+
119
+ ### Changed
120
+ - Mesh now supports three modes: `autonomous`, `p2p`, `distributed`
121
+ - Agent base class now includes P2P support
122
+
123
+ ---
124
+
125
+ ## [0.1.0] - 2026-01-01
126
+
127
+ ### Added
128
+ - Initial release
129
+ - AutoAgent profile with LLM-powered code generation
130
+ - Workflow engine with dependency management
131
+ - Sandbox execution (local and remote)
132
+ - Auto-repair for failed code
133
+ - Internet search integration (DuckDuckGo)
134
+ - Multi-provider LLM support (Claude, OpenAI, Azure, Gemini)
135
+ - Result storage and code registry
136
+
137
+ ---
138
+
139
+ *JarvisCore Framework - Build autonomous AI agents with P2P mesh networking.*
@@ -766,6 +766,6 @@ LOG_DIRECTORY=/tmp/jarviscore-logs
766
766
 
767
767
  ## Version
768
768
 
769
- Configuration Guide for JarvisCore v0.2.1
769
+ Configuration Guide for JarvisCore v0.3.1
770
770
 
771
771
  Last Updated: 2026-01-23