jarviscore-framework 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.
Files changed (55) hide show
  1. examples/calculator_agent_example.py +77 -0
  2. examples/multi_agent_workflow.py +132 -0
  3. examples/research_agent_example.py +76 -0
  4. jarviscore/__init__.py +54 -0
  5. jarviscore/cli/__init__.py +7 -0
  6. jarviscore/cli/__main__.py +33 -0
  7. jarviscore/cli/check.py +404 -0
  8. jarviscore/cli/smoketest.py +371 -0
  9. jarviscore/config/__init__.py +7 -0
  10. jarviscore/config/settings.py +128 -0
  11. jarviscore/core/__init__.py +7 -0
  12. jarviscore/core/agent.py +163 -0
  13. jarviscore/core/mesh.py +463 -0
  14. jarviscore/core/profile.py +64 -0
  15. jarviscore/docs/API_REFERENCE.md +932 -0
  16. jarviscore/docs/CONFIGURATION.md +753 -0
  17. jarviscore/docs/GETTING_STARTED.md +600 -0
  18. jarviscore/docs/TROUBLESHOOTING.md +424 -0
  19. jarviscore/docs/USER_GUIDE.md +983 -0
  20. jarviscore/execution/__init__.py +94 -0
  21. jarviscore/execution/code_registry.py +298 -0
  22. jarviscore/execution/generator.py +268 -0
  23. jarviscore/execution/llm.py +430 -0
  24. jarviscore/execution/repair.py +283 -0
  25. jarviscore/execution/result_handler.py +332 -0
  26. jarviscore/execution/sandbox.py +555 -0
  27. jarviscore/execution/search.py +281 -0
  28. jarviscore/orchestration/__init__.py +18 -0
  29. jarviscore/orchestration/claimer.py +101 -0
  30. jarviscore/orchestration/dependency.py +143 -0
  31. jarviscore/orchestration/engine.py +292 -0
  32. jarviscore/orchestration/status.py +96 -0
  33. jarviscore/p2p/__init__.py +23 -0
  34. jarviscore/p2p/broadcaster.py +353 -0
  35. jarviscore/p2p/coordinator.py +364 -0
  36. jarviscore/p2p/keepalive.py +361 -0
  37. jarviscore/p2p/swim_manager.py +290 -0
  38. jarviscore/profiles/__init__.py +6 -0
  39. jarviscore/profiles/autoagent.py +264 -0
  40. jarviscore/profiles/customagent.py +137 -0
  41. jarviscore_framework-0.1.0.dist-info/METADATA +136 -0
  42. jarviscore_framework-0.1.0.dist-info/RECORD +55 -0
  43. jarviscore_framework-0.1.0.dist-info/WHEEL +5 -0
  44. jarviscore_framework-0.1.0.dist-info/licenses/LICENSE +21 -0
  45. jarviscore_framework-0.1.0.dist-info/top_level.txt +3 -0
  46. tests/conftest.py +44 -0
  47. tests/test_agent.py +165 -0
  48. tests/test_autoagent.py +140 -0
  49. tests/test_autoagent_day4.py +186 -0
  50. tests/test_customagent.py +248 -0
  51. tests/test_integration.py +293 -0
  52. tests/test_llm_fallback.py +185 -0
  53. tests/test_mesh.py +356 -0
  54. tests/test_p2p_integration.py +375 -0
  55. tests/test_remote_sandbox.py +116 -0
@@ -0,0 +1,600 @@
1
+ # Getting Started with JarvisCore
2
+
3
+ Build your first AI agent in 5 minutes!
4
+
5
+ ---
6
+
7
+ ## What You'll Build
8
+
9
+ An **AutoAgent** that takes natural language prompts and automatically:
10
+ 1. Generates Python code using an LLM
11
+ 2. Executes the code securely
12
+ 3. Returns the result
13
+
14
+ **No manual coding required** - just describe what you want!
15
+
16
+ ---
17
+
18
+ ## Prerequisites
19
+
20
+ - ✅ Python 3.10 or higher
21
+ - ✅ An API key from one of these LLM providers:
22
+ - [Claude (Anthropic)](https://console.anthropic.com/) - Recommended
23
+ - [Azure OpenAI](https://azure.microsoft.com/en-us/products/ai-services/openai-service)
24
+ - [Google Gemini](https://ai.google.dev/)
25
+ - Local vLLM server (free, self-hosted)
26
+
27
+ ---
28
+
29
+ ## Step 1: Install JarvisCore (30 seconds)
30
+
31
+ ```bash
32
+ pip install jarviscore
33
+ ```
34
+
35
+ ---
36
+
37
+ ## Step 2: Configure Your LLM (2 minutes)
38
+
39
+ Create a `.env` file in your project directory:
40
+
41
+ ```bash
42
+ # Copy the example config
43
+ cp .env.example .env
44
+ ```
45
+
46
+ Edit `.env` and add **ONE** of these API keys:
47
+
48
+ ### Option 1: Claude (Recommended)
49
+ ```bash
50
+ CLAUDE_API_KEY=sk-ant-your-key-here
51
+ ```
52
+
53
+ ### Option 2: Azure OpenAI
54
+ ```bash
55
+ AZURE_API_KEY=your-key-here
56
+ AZURE_ENDPOINT=https://your-resource.openai.azure.com
57
+ AZURE_DEPLOYMENT=gpt-4o
58
+ ```
59
+
60
+ ### Option 3: Google Gemini
61
+ ```bash
62
+ GEMINI_API_KEY=your-key-here
63
+ ```
64
+
65
+ ### Option 4: Local vLLM (Free, Self-Hosted)
66
+ ```bash
67
+ LLM_ENDPOINT=http://localhost:8000
68
+ LLM_MODEL=Qwen/Qwen2.5-Coder-32B-Instruct
69
+ ```
70
+
71
+ **Tip:** JarvisCore automatically tries providers in this order:
72
+ Claude → Azure → Gemini → vLLM
73
+
74
+ ---
75
+
76
+ ## Step 3: Validate Your Setup (30 seconds)
77
+
78
+ Run the health check to ensure everything works:
79
+
80
+ ```bash
81
+ # Basic check
82
+ python -m jarviscore.cli.check
83
+
84
+ # Test LLM connectivity
85
+ python -m jarviscore.cli.check --validate-llm
86
+ ```
87
+
88
+ You should see:
89
+ ```
90
+ ✓ Python Version: OK
91
+ ✓ JarvisCore Package: OK
92
+ ✓ Dependencies: OK
93
+ ✓ .env File: OK
94
+ ✓ Claude/Azure/Gemini: OK
95
+ ```
96
+
97
+ Run the smoke test for end-to-end validation:
98
+
99
+ ```bash
100
+ python -m jarviscore.cli.smoketest
101
+ ```
102
+
103
+ ✅ **If all tests pass**, you're ready to build agents!
104
+
105
+ ---
106
+
107
+ ## Step 4: Build Your First Agent (3 minutes)
108
+
109
+ Create a file called `my_first_agent.py`:
110
+
111
+ ```python
112
+ import asyncio
113
+ from jarviscore import Mesh
114
+ from jarviscore.profiles import AutoAgent
115
+
116
+
117
+ # 1. Define your agent
118
+ class CalculatorAgent(AutoAgent):
119
+ role = "calculator"
120
+ capabilities = ["math", "calculations"]
121
+ system_prompt = """
122
+ You are a math expert. Generate Python code to solve problems.
123
+ Always store the result in a variable named 'result'.
124
+ """
125
+
126
+
127
+ # 2. Create and run
128
+ async def main():
129
+ # Initialize the mesh
130
+ mesh = Mesh(mode="autonomous")
131
+
132
+ # Add your agent
133
+ mesh.add(CalculatorAgent)
134
+
135
+ # Start the mesh
136
+ await mesh.start()
137
+
138
+ # Execute a task with a simple prompt
139
+ results = await mesh.workflow("calc-workflow", [
140
+ {
141
+ "agent": "calculator",
142
+ "task": "Calculate the factorial of 10"
143
+ }
144
+ ])
145
+
146
+ # Get the result
147
+ result = results[0]
148
+ print(f"Status: {result['status']}")
149
+ print(f"Output: {result['output']}")
150
+ print(f"Execution time: {result['execution_time']:.2f}s")
151
+
152
+ # Stop the mesh
153
+ await mesh.stop()
154
+
155
+
156
+ if __name__ == "__main__":
157
+ asyncio.run(main())
158
+ ```
159
+
160
+ ### Run it:
161
+
162
+ ```bash
163
+ python my_first_agent.py
164
+ ```
165
+
166
+ ### Expected Output:
167
+
168
+ ```
169
+ Status: success
170
+ Output: 3628800
171
+ Execution time: 4.23s
172
+ ```
173
+
174
+ **🎉 Congratulations!** You just built an AI agent with zero manual coding!
175
+
176
+ ---
177
+
178
+ ## What Just Happened?
179
+
180
+ Behind the scenes, JarvisCore:
181
+
182
+ 1. **Received your prompt**: "Calculate the factorial of 10"
183
+ 2. **Generated Python code** using Claude/Azure/Gemini:
184
+ ```python
185
+ def factorial(n):
186
+ if n == 0 or n == 1:
187
+ return 1
188
+ return n * factorial(n - 1)
189
+
190
+ result = factorial(10)
191
+ ```
192
+ 3. **Executed the code** safely in a sandbox
193
+ 4. **Returned the result**: 3628800
194
+
195
+ All from a single natural language prompt!
196
+
197
+ ---
198
+
199
+ ## Step 5: Try More Complex Examples
200
+
201
+ ### Example 1: Data Processing
202
+
203
+ ```python
204
+ class DataAgent(AutoAgent):
205
+ role = "data_analyst"
206
+ capabilities = ["data_processing", "statistics"]
207
+ system_prompt = "You are a data analyst. Generate Python code for data tasks."
208
+
209
+
210
+ async def analyze_data():
211
+ mesh = Mesh(mode="autonomous")
212
+ mesh.add(DataAgent)
213
+ await mesh.start()
214
+
215
+ results = await mesh.workflow("data-workflow", [
216
+ {
217
+ "agent": "data_analyst",
218
+ "task": """
219
+ Given this list: [10, 20, 30, 40, 50]
220
+ Calculate: mean, median, min, max, sum
221
+ Return as a dict
222
+ """
223
+ }
224
+ ])
225
+
226
+ print(results[0]['output'])
227
+ # Output: {'mean': 30.0, 'median': 30, 'min': 10, 'max': 50, 'sum': 150}
228
+
229
+ await mesh.stop()
230
+ ```
231
+
232
+ ### Example 2: Text Processing
233
+
234
+ ```python
235
+ class TextAgent(AutoAgent):
236
+ role = "text_processor"
237
+ capabilities = ["text", "nlp"]
238
+ system_prompt = "You are a text processing expert."
239
+
240
+
241
+ async def process_text():
242
+ mesh = Mesh(mode="autonomous")
243
+ mesh.add(TextAgent)
244
+ await mesh.start()
245
+
246
+ results = await mesh.workflow("text-workflow", [
247
+ {
248
+ "agent": "text_processor",
249
+ "task": """
250
+ Count the words in this sentence:
251
+ "JarvisCore makes building AI agents incredibly easy"
252
+ """
253
+ }
254
+ ])
255
+
256
+ print(results[0]['output']) # Output: 7
257
+
258
+ await mesh.stop()
259
+ ```
260
+
261
+ ### Example 3: Multi-Step Workflow
262
+
263
+ ```python
264
+ async def multi_step_workflow():
265
+ mesh = Mesh(mode="autonomous")
266
+ mesh.add(CalculatorAgent)
267
+ mesh.add(DataAgent)
268
+ await mesh.start()
269
+
270
+ results = await mesh.workflow("multi-step", [
271
+ {
272
+ "id": "step1",
273
+ "agent": "calculator",
274
+ "task": "Calculate 5 factorial"
275
+ },
276
+ {
277
+ "id": "step2",
278
+ "agent": "data_analyst",
279
+ "task": "Take the result from step1 and calculate its square root",
280
+ "dependencies": ["step1"] # Waits for step1 to complete
281
+ }
282
+ ])
283
+
284
+ print(f"Factorial(5): {results[0]['output']}") # 120
285
+ print(f"Square root: {results[1]['output']:.2f}") # 10.95
286
+
287
+ await mesh.stop()
288
+ ```
289
+
290
+ ---
291
+
292
+ ## Key Concepts
293
+
294
+ ### 1. AutoAgent Profile
295
+
296
+ The `AutoAgent` profile handles the "prompt → code → result" workflow automatically:
297
+
298
+ ```python
299
+ class MyAgent(AutoAgent):
300
+ role = "unique_name" # Unique identifier
301
+ capabilities = ["skill1", "skill2"] # What it can do
302
+ system_prompt = "Instructions for the LLM" # How to generate code
303
+ ```
304
+
305
+ ### 2. Mesh
306
+
307
+ The `Mesh` is the orchestrator that manages agents and workflows:
308
+
309
+ ```python
310
+ mesh = Mesh(mode="autonomous") # Autonomous mode for AutoAgent
311
+ mesh.add(MyAgent) # Register your agent
312
+ await mesh.start() # Initialize
313
+ results = await mesh.workflow(...) # Execute tasks
314
+ await mesh.stop() # Cleanup
315
+ ```
316
+
317
+ ### 3. Workflow
318
+
319
+ A workflow is a list of tasks to execute:
320
+
321
+ ```python
322
+ results = await mesh.workflow("workflow-id", [
323
+ {
324
+ "agent": "agent_role", # Which agent to use
325
+ "task": "What to do", # Natural language prompt
326
+ "dependencies": [] # Optional: wait for other steps
327
+ }
328
+ ])
329
+ ```
330
+
331
+ ### 4. Results
332
+
333
+ Each task returns a result dict:
334
+
335
+ ```python
336
+ {
337
+ "status": "success", # success or failure
338
+ "output": 42, # The actual result
339
+ "execution_time": 3.14, # Seconds
340
+ "repairs": 0, # Auto-fix attempts
341
+ "code": "result = 6 * 7", # Generated code
342
+ "agent_id": "calculator-abc123"
343
+ }
344
+ ```
345
+
346
+ ---
347
+
348
+ ## Configuration Options
349
+
350
+ ### Sandbox Mode
351
+
352
+ Choose between local or remote code execution:
353
+
354
+ ```bash
355
+ # Local (default) - runs on your machine
356
+ SANDBOX_MODE=local
357
+
358
+ # Remote - runs on Azure Container Apps (more secure)
359
+ SANDBOX_MODE=remote
360
+ SANDBOX_SERVICE_URL=https://your-sandbox-service.com
361
+ ```
362
+
363
+ ### LLM Settings
364
+
365
+ Fine-tune LLM behavior:
366
+
367
+ ```bash
368
+ # Model selection (provider-specific)
369
+ CLAUDE_MODEL=claude-sonnet-4 # Claude
370
+ AZURE_DEPLOYMENT=gpt-4o # Azure
371
+ GEMINI_MODEL=gemini-1.5-flash # Gemini
372
+ LLM_MODEL=Qwen/Qwen2.5-Coder-32B # vLLM
373
+
374
+ # Generation parameters
375
+ LLM_TEMPERATURE=0.0 # 0.0 = deterministic, 1.0 = creative
376
+ LLM_MAX_TOKENS=2000 # Max response length
377
+ LLM_TIMEOUT=120 # Request timeout (seconds)
378
+ ```
379
+
380
+ ### Logging
381
+
382
+ Control log verbosity:
383
+
384
+ ```bash
385
+ LOG_LEVEL=INFO # DEBUG, INFO, WARNING, ERROR, CRITICAL
386
+ ```
387
+
388
+ ---
389
+
390
+ ## Common Patterns
391
+
392
+ ### Pattern 1: Error Handling
393
+
394
+ ```python
395
+ try:
396
+ results = await mesh.workflow("workflow-1", [
397
+ {"agent": "calculator", "task": "Calculate 1/0"}
398
+ ])
399
+
400
+ if results[0]['status'] == 'failure':
401
+ print(f"Error: {results[0]['error']}")
402
+ # The agent automatically attempted repairs
403
+ print(f"Repair attempts: {results[0]['repairs']}")
404
+
405
+ except Exception as e:
406
+ print(f"Workflow failed: {e}")
407
+ ```
408
+
409
+ ### Pattern 2: Dynamic Tasks
410
+
411
+ ```python
412
+ user_input = "Calculate the area of a circle with radius 5"
413
+
414
+ results = await mesh.workflow("dynamic", [
415
+ {"agent": "calculator", "task": user_input}
416
+ ])
417
+
418
+ print(results[0]['output']) # 78.54
419
+ ```
420
+
421
+ ### Pattern 3: Context Passing
422
+
423
+ Pass data between steps:
424
+
425
+ ```python
426
+ results = await mesh.workflow("context-workflow", [
427
+ {
428
+ "id": "generate",
429
+ "agent": "data_analyst",
430
+ "task": "Generate a list of 10 random numbers between 1 and 100"
431
+ },
432
+ {
433
+ "id": "analyze",
434
+ "agent": "data_analyst",
435
+ "task": "Calculate statistics on the numbers from step 'generate'",
436
+ "dependencies": ["generate"]
437
+ }
438
+ ])
439
+
440
+ numbers = results[0]['output']
441
+ stats = results[1]['output']
442
+ print(f"Numbers: {numbers}")
443
+ print(f"Statistics: {stats}")
444
+ ```
445
+
446
+ ---
447
+
448
+ ## Troubleshooting
449
+
450
+ ### Issue: "No LLM providers configured"
451
+
452
+ **Solution:** Check your `.env` file has a valid API key:
453
+ ```bash
454
+ python -m jarviscore.cli.check --validate-llm
455
+ ```
456
+
457
+ ### Issue: "Task failed: Unknown error"
458
+
459
+ **Solution:** Check logs for details:
460
+ ```bash
461
+ ls -la logs/
462
+ cat logs/<agent>/<latest>.json
463
+ ```
464
+
465
+ Run smoke test with verbose output:
466
+ ```bash
467
+ python -m jarviscore.cli.smoketest --verbose
468
+ ```
469
+
470
+ ### Issue: Slow execution
471
+
472
+ **Causes:**
473
+ 1. LLM latency (2-5s per request)
474
+ 2. Complex prompts
475
+ 3. Network issues
476
+
477
+ **Solutions:**
478
+ - Use faster models (Claude Haiku, Gemini Flash)
479
+ - Simplify prompts
480
+ - Use local vLLM for zero-latency
481
+
482
+ ### Issue: Generated code has errors
483
+
484
+ **Good news:** AutoAgent automatically attempts to fix errors!
485
+
486
+ It will:
487
+ 1. Detect the error
488
+ 2. Ask the LLM to fix the code
489
+ 3. Retry execution (up to 3 times)
490
+
491
+ Check `repairs` in the result to see how many fixes were needed.
492
+
493
+ ---
494
+
495
+ ## Next Steps
496
+
497
+ 1. **Read the User Guide**: Complete documentation at [USER_GUIDE.md](USER_GUIDE.md)
498
+ 2. **Explore Examples**: Check out `examples/` directory
499
+ 3. **Try the API Reference**: [API_REFERENCE.md](API_REFERENCE.md)
500
+ 4. **Configuration Guide**: [CONFIGURATION.md](CONFIGURATION.md)
501
+ 5. **Troubleshooting**: [TROUBLESHOOTING.md](TROUBLESHOOTING.md)
502
+
503
+ ---
504
+
505
+ ## Best Practices
506
+
507
+ ### ✅ DO
508
+
509
+ - **Be specific in prompts**: "Calculate factorial of 10" > "Do math"
510
+ - **Test with simple tasks first**: Validate your setup works
511
+ - **Use appropriate models**: Haiku/Flash for simple tasks, Opus/GPT-4 for complex
512
+ - **Monitor costs**: Check LLM usage if using paid APIs
513
+ - **Read error messages**: They contain helpful hints
514
+
515
+ ### ❌ DON'T
516
+
517
+ - **Use vague prompts**: "Do something" won't work well
518
+ - **Expect instant results**: LLM generation takes 2-5 seconds
519
+ - **Skip validation**: Always run health check after setup
520
+ - **Commit API keys**: Keep `.env` out of version control
521
+ - **Ignore logs**: They help debug issues
522
+
523
+ ---
524
+
525
+ ## FAQ
526
+
527
+ ### Q: How much does it cost?
528
+
529
+ **A:** Depends on your LLM provider:
530
+ - **Claude**: ~$3-15 per million tokens (most expensive but best quality)
531
+ - **Azure**: ~$3-15 per million tokens (enterprise-grade)
532
+ - **Gemini**: $0.10-5 per million tokens (cheapest cloud option)
533
+ - **vLLM**: FREE (self-hosted, no API costs)
534
+
535
+ A typical simple task uses ~500 tokens = $0.0015 with Claude.
536
+
537
+ ### Q: Is the code execution safe?
538
+
539
+ **A:** Yes! Code runs in an isolated sandbox:
540
+ - **Local mode**: Restricted Python environment (no file/network access)
541
+ - **Remote mode**: Azure Container Apps (fully isolated containers)
542
+
543
+ ### Q: Can I use my own LLM?
544
+
545
+ **A:** Yes! Point `LLM_ENDPOINT` to any OpenAI-compatible API:
546
+ ```bash
547
+ LLM_ENDPOINT=http://localhost:8000 # Local vLLM
548
+ LLM_ENDPOINT=https://your-api.com # Custom endpoint
549
+ ```
550
+
551
+ ### Q: What if the LLM generates bad code?
552
+
553
+ **A:** AutoAgent automatically detects and fixes errors:
554
+ 1. Catches syntax/runtime errors
555
+ 2. Sends error to LLM with fix instructions
556
+ 3. Retries with corrected code (up to 3 attempts)
557
+
558
+ Check `repairs` in the result to see how many fixes were needed.
559
+
560
+ ### Q: Can I see the generated code?
561
+
562
+ **A:** Yes! It's in the result:
563
+ ```python
564
+ result = results[0]
565
+ print(result['code']) # Shows the generated Python code
566
+ ```
567
+
568
+ Or check logs:
569
+ ```bash
570
+ cat logs/<agent-role>/<result-id>.json
571
+ ```
572
+
573
+ ### Q: How do I deploy this in production?
574
+
575
+ **A:** See the User Guide for:
576
+ - Remote sandbox configuration (Azure Container Apps)
577
+ - High-availability setup
578
+ - Monitoring and logging
579
+ - Cost optimization
580
+
581
+ ---
582
+
583
+ ## Support
584
+
585
+ Need help?
586
+
587
+ 1. **Check docs**: [USER_GUIDE.md](USER_GUIDE.md) | [TROUBLESHOOTING.md](TROUBLESHOOTING.md)
588
+ 2. **Run diagnostics**:
589
+ ```bash
590
+ python -m jarviscore.cli.check --verbose
591
+ python -m jarviscore.cli.smoketest --verbose
592
+ ```
593
+ 3. **Check logs**: `cat logs/<agent>/<latest>.json`
594
+ 4. **Report issues**: [GitHub Issues](https://github.com/yourusername/jarviscore/issues)
595
+
596
+ ---
597
+
598
+ **🚀 Happy building with JarvisCore!**
599
+
600
+ *Built for the AutoAgent/Prompt-Dev generation - where AI writes the code, you write the prompts.*