agent-bootstrap-kit 1.0.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.
- agent_bootstrap_kit-1.0.0/PKG-INFO +78 -0
- agent_bootstrap_kit-1.0.0/README.md +64 -0
- agent_bootstrap_kit-1.0.0/agent_bootstrap_kit/__init__.py +18 -0
- agent_bootstrap_kit-1.0.0/agent_bootstrap_kit/cli.py +37 -0
- agent_bootstrap_kit-1.0.0/agent_bootstrap_kit/extractor.py +94 -0
- agent_bootstrap_kit-1.0.0/agent_bootstrap_kit/scripts/EXAM_DAY_REFERENCE.py +142 -0
- agent_bootstrap_kit-1.0.0/agent_bootstrap_kit/scripts/__init__.py +0 -0
- agent_bootstrap_kit-1.0.0/agent_bootstrap_kit/scripts/autogen/3_autogen_two_agent.py +75 -0
- agent_bootstrap_kit-1.0.0/agent_bootstrap_kit/scripts/autogen/4_autogen_tool_use.py +106 -0
- agent_bootstrap_kit-1.0.0/agent_bootstrap_kit/scripts/autogen/__init__.py +0 -0
- agent_bootstrap_kit-1.0.0/agent_bootstrap_kit/scripts/azure_ai_agent/7_azure_agent_thread.py +156 -0
- agent_bootstrap_kit-1.0.0/agent_bootstrap_kit/scripts/azure_ai_agent/__init__.py +0 -0
- agent_bootstrap_kit-1.0.0/agent_bootstrap_kit/scripts/plain_openai/1_multiturn_chat.py +82 -0
- agent_bootstrap_kit-1.0.0/agent_bootstrap_kit/scripts/plain_openai/2_simple_agent_tools.py +166 -0
- agent_bootstrap_kit-1.0.0/agent_bootstrap_kit/scripts/plain_openai/__init__.py +0 -0
- agent_bootstrap_kit-1.0.0/agent_bootstrap_kit/scripts/semantic_kernel/5_sk_basic_agent.py +135 -0
- agent_bootstrap_kit-1.0.0/agent_bootstrap_kit/scripts/semantic_kernel/6_sk_workflow.py +184 -0
- agent_bootstrap_kit-1.0.0/agent_bootstrap_kit/scripts/semantic_kernel/__init__.py +0 -0
- agent_bootstrap_kit-1.0.0/agent_bootstrap_kit/scripts/setup.sh +38 -0
- agent_bootstrap_kit-1.0.0/agent_bootstrap_kit.egg-info/PKG-INFO +78 -0
- agent_bootstrap_kit-1.0.0/agent_bootstrap_kit.egg-info/SOURCES.txt +25 -0
- agent_bootstrap_kit-1.0.0/agent_bootstrap_kit.egg-info/dependency_links.txt +1 -0
- agent_bootstrap_kit-1.0.0/agent_bootstrap_kit.egg-info/entry_points.txt +2 -0
- agent_bootstrap_kit-1.0.0/agent_bootstrap_kit.egg-info/requires.txt +6 -0
- agent_bootstrap_kit-1.0.0/agent_bootstrap_kit.egg-info/top_level.txt +1 -0
- agent_bootstrap_kit-1.0.0/pyproject.toml +33 -0
- agent_bootstrap_kit-1.0.0/setup.cfg +4 -0
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: agent-bootstrap-kit
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: OpenAI agent bootstrap scripts for assessments
|
|
5
|
+
License: MIT
|
|
6
|
+
Requires-Python: >=3.9
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
Requires-Dist: openai>=1.0.0
|
|
9
|
+
Requires-Dist: python-dotenv>=1.0.0
|
|
10
|
+
Requires-Dist: pyautogen>=0.2.0
|
|
11
|
+
Requires-Dist: semantic-kernel>=1.0.0
|
|
12
|
+
Requires-Dist: azure-ai-projects>=1.0.0
|
|
13
|
+
Requires-Dist: azure-identity>=1.0.0
|
|
14
|
+
|
|
15
|
+
# agent-bootstrap-kit
|
|
16
|
+
|
|
17
|
+
Bootstrap scripts for building OpenAI agents — multi-turn chat, tool use, AutoGen, Semantic Kernel, and Azure AI Agent Service.
|
|
18
|
+
|
|
19
|
+
## Install
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
pip install agent-bootstrap-kit
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Extract scripts to your current folder
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
agent-bootstrap
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Or in Python:
|
|
32
|
+
|
|
33
|
+
```python
|
|
34
|
+
from agent_bootstrap_kit import extract
|
|
35
|
+
extract()
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## What gets extracted
|
|
39
|
+
|
|
40
|
+
```
|
|
41
|
+
plain_openai/
|
|
42
|
+
1_multiturn_chat.py # Multi-turn conversation agent
|
|
43
|
+
2_simple_agent_tools.py # Agent with tool/function calling
|
|
44
|
+
|
|
45
|
+
autogen/
|
|
46
|
+
3_autogen_two_agent.py # AutoGen two-agent conversation
|
|
47
|
+
4_autogen_tool_use.py # AutoGen agent with tools
|
|
48
|
+
|
|
49
|
+
semantic_kernel/
|
|
50
|
+
5_sk_basic_agent.py # Semantic Kernel agent with plugin
|
|
51
|
+
6_sk_workflow.py # Semantic Kernel multi-step pipeline
|
|
52
|
+
|
|
53
|
+
azure_ai_agent/
|
|
54
|
+
7_azure_agent_thread.py # Azure AI Agent Service (thread-based)
|
|
55
|
+
|
|
56
|
+
EXAM_DAY_REFERENCE.py # Quick reference — which script to use when
|
|
57
|
+
setup.sh # Install all dependencies in one command
|
|
58
|
+
.env.template # Copy → .env, add your API key
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Quick start after extraction
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
# 1. Add your API key
|
|
65
|
+
cp .env.template .env
|
|
66
|
+
# Edit .env: OPENAI_API_KEY=sk-...
|
|
67
|
+
|
|
68
|
+
# 2. Install dependencies
|
|
69
|
+
bash setup.sh
|
|
70
|
+
|
|
71
|
+
# 3. Run a script
|
|
72
|
+
python plain_openai/1_multiturn_chat.py
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Requirements
|
|
76
|
+
|
|
77
|
+
- Python 3.9+
|
|
78
|
+
- An OpenAI API key
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# agent-bootstrap-kit
|
|
2
|
+
|
|
3
|
+
Bootstrap scripts for building OpenAI agents — multi-turn chat, tool use, AutoGen, Semantic Kernel, and Azure AI Agent Service.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install agent-bootstrap-kit
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Extract scripts to your current folder
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
agent-bootstrap
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Or in Python:
|
|
18
|
+
|
|
19
|
+
```python
|
|
20
|
+
from agent_bootstrap_kit import extract
|
|
21
|
+
extract()
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## What gets extracted
|
|
25
|
+
|
|
26
|
+
```
|
|
27
|
+
plain_openai/
|
|
28
|
+
1_multiturn_chat.py # Multi-turn conversation agent
|
|
29
|
+
2_simple_agent_tools.py # Agent with tool/function calling
|
|
30
|
+
|
|
31
|
+
autogen/
|
|
32
|
+
3_autogen_two_agent.py # AutoGen two-agent conversation
|
|
33
|
+
4_autogen_tool_use.py # AutoGen agent with tools
|
|
34
|
+
|
|
35
|
+
semantic_kernel/
|
|
36
|
+
5_sk_basic_agent.py # Semantic Kernel agent with plugin
|
|
37
|
+
6_sk_workflow.py # Semantic Kernel multi-step pipeline
|
|
38
|
+
|
|
39
|
+
azure_ai_agent/
|
|
40
|
+
7_azure_agent_thread.py # Azure AI Agent Service (thread-based)
|
|
41
|
+
|
|
42
|
+
EXAM_DAY_REFERENCE.py # Quick reference — which script to use when
|
|
43
|
+
setup.sh # Install all dependencies in one command
|
|
44
|
+
.env.template # Copy → .env, add your API key
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Quick start after extraction
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
# 1. Add your API key
|
|
51
|
+
cp .env.template .env
|
|
52
|
+
# Edit .env: OPENAI_API_KEY=sk-...
|
|
53
|
+
|
|
54
|
+
# 2. Install dependencies
|
|
55
|
+
bash setup.sh
|
|
56
|
+
|
|
57
|
+
# 3. Run a script
|
|
58
|
+
python plain_openai/1_multiturn_chat.py
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Requirements
|
|
62
|
+
|
|
63
|
+
- Python 3.9+
|
|
64
|
+
- An OpenAI API key
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"""
|
|
2
|
+
agent_bootstrap_kit
|
|
3
|
+
===================
|
|
4
|
+
Bootstrap scripts for OpenAI agent assessments.
|
|
5
|
+
|
|
6
|
+
Usage on the VM:
|
|
7
|
+
pip install agent-bootstrap-kit
|
|
8
|
+
agent-bootstrap # extracts all files to current folder
|
|
9
|
+
|
|
10
|
+
OR in Python:
|
|
11
|
+
from agent_bootstrap_kit import extract
|
|
12
|
+
extract()
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
from agent_bootstrap_kit.extractor import extract
|
|
16
|
+
|
|
17
|
+
__version__ = "1.0.0"
|
|
18
|
+
__all__ = ["extract"]
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"""
|
|
2
|
+
cli.py
|
|
3
|
+
======
|
|
4
|
+
Entry point for the "agent-bootstrap" command-line tool.
|
|
5
|
+
|
|
6
|
+
After pip install, this lets you just type:
|
|
7
|
+
agent-bootstrap
|
|
8
|
+
|
|
9
|
+
...and it extracts all scripts into your current folder.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
import argparse
|
|
13
|
+
from agent_bootstrap_kit.extractor import extract
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def main():
|
|
17
|
+
parser = argparse.ArgumentParser(
|
|
18
|
+
prog="agent-bootstrap",
|
|
19
|
+
description="Extract OpenAI agent bootstrap scripts into your current folder"
|
|
20
|
+
)
|
|
21
|
+
parser.add_argument(
|
|
22
|
+
"--dest",
|
|
23
|
+
default=".",
|
|
24
|
+
help="Destination folder (default: current directory)"
|
|
25
|
+
)
|
|
26
|
+
parser.add_argument(
|
|
27
|
+
"--version",
|
|
28
|
+
action="version",
|
|
29
|
+
version="agent-bootstrap-kit 1.0.0"
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
args = parser.parse_args()
|
|
33
|
+
extract(destination=args.dest)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
if __name__ == "__main__":
|
|
37
|
+
main()
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"""
|
|
2
|
+
extractor.py
|
|
3
|
+
============
|
|
4
|
+
Copies all bootstrap scripts from the installed package
|
|
5
|
+
into the user's current working directory.
|
|
6
|
+
|
|
7
|
+
This is the magic that makes "pip install → files appear" work.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
import os
|
|
11
|
+
import shutil
|
|
12
|
+
import pathlib
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def extract(destination: str = ".") -> None:
|
|
16
|
+
"""
|
|
17
|
+
Extract all bootstrap scripts into the destination folder.
|
|
18
|
+
|
|
19
|
+
Args:
|
|
20
|
+
destination: Path to copy files into. Defaults to current directory.
|
|
21
|
+
|
|
22
|
+
Usage:
|
|
23
|
+
from agent_bootstrap_kit import extract
|
|
24
|
+
extract() # copies into current folder
|
|
25
|
+
extract("./mywork") # copies into ./mywork
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
# Find where THIS package is installed on disk
|
|
29
|
+
# __file__ = .../site-packages/agent_bootstrap_kit/extractor.py
|
|
30
|
+
package_dir = pathlib.Path(__file__).parent
|
|
31
|
+
scripts_dir = package_dir / "scripts"
|
|
32
|
+
|
|
33
|
+
if not scripts_dir.exists():
|
|
34
|
+
print(f"ERROR: scripts directory not found at {scripts_dir}")
|
|
35
|
+
return
|
|
36
|
+
|
|
37
|
+
dest = pathlib.Path(destination).resolve()
|
|
38
|
+
dest.mkdir(parents=True, exist_ok=True)
|
|
39
|
+
|
|
40
|
+
print(f"\nExtracting agent bootstrap scripts to: {dest}\n")
|
|
41
|
+
|
|
42
|
+
copied = []
|
|
43
|
+
skipped = []
|
|
44
|
+
|
|
45
|
+
# Walk every file inside scripts/ and copy to destination
|
|
46
|
+
for src_path in scripts_dir.rglob("*"):
|
|
47
|
+
if src_path.is_dir():
|
|
48
|
+
continue # directories are created automatically below
|
|
49
|
+
|
|
50
|
+
# Compute relative path from scripts_dir
|
|
51
|
+
# e.g. scripts/plain_openai/1_multiturn_chat.py → plain_openai/1_multiturn_chat.py
|
|
52
|
+
relative = src_path.relative_to(scripts_dir)
|
|
53
|
+
dst_path = dest / relative
|
|
54
|
+
|
|
55
|
+
# Create parent directories if needed
|
|
56
|
+
dst_path.parent.mkdir(parents=True, exist_ok=True)
|
|
57
|
+
|
|
58
|
+
# Don't overwrite files the user may have already edited
|
|
59
|
+
if dst_path.exists():
|
|
60
|
+
skipped.append(str(relative))
|
|
61
|
+
continue
|
|
62
|
+
|
|
63
|
+
shutil.copy2(src_path, dst_path)
|
|
64
|
+
copied.append(str(relative))
|
|
65
|
+
|
|
66
|
+
# Print a clean summary
|
|
67
|
+
if copied:
|
|
68
|
+
print(" ✓ Copied:")
|
|
69
|
+
for f in sorted(copied):
|
|
70
|
+
print(f" {f}")
|
|
71
|
+
|
|
72
|
+
if skipped:
|
|
73
|
+
print("\n ⚠ Skipped (already exists):")
|
|
74
|
+
for f in sorted(skipped):
|
|
75
|
+
print(f" {f}")
|
|
76
|
+
|
|
77
|
+
print(f"\n Done. {len(copied)} file(s) extracted.\n")
|
|
78
|
+
|
|
79
|
+
# Print next steps
|
|
80
|
+
print("=" * 55)
|
|
81
|
+
print("NEXT STEPS:")
|
|
82
|
+
print("=" * 55)
|
|
83
|
+
print("1. Rename .env.template → .env")
|
|
84
|
+
print(" Add your key: OPENAI_API_KEY=sk-...")
|
|
85
|
+
print("")
|
|
86
|
+
print("2. Install dependencies:")
|
|
87
|
+
print(" bash setup.sh")
|
|
88
|
+
print(" (or: pip install openai pyautogen semantic-kernel python-dotenv)")
|
|
89
|
+
print("")
|
|
90
|
+
print("3. Open EXAM_DAY_REFERENCE.py to pick the right script")
|
|
91
|
+
print("")
|
|
92
|
+
print("4. Run a script, e.g.:")
|
|
93
|
+
print(" python plain_openai/1_multiturn_chat.py")
|
|
94
|
+
print("=" * 55)
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
# ══════════════════════════════════════════════════════════════════
|
|
2
|
+
# EXAM DAY QUICK REFERENCE — OpenAI Agent Assessment
|
|
3
|
+
# Keep this open. Match the task to the right script.
|
|
4
|
+
# ══════════════════════════════════════════════════════════════════
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
# ─────────────────────────────────────────────────────────────────
|
|
8
|
+
# STEP 0: FIRST THING — Create your .env file
|
|
9
|
+
# ─────────────────────────────────────────────────────────────────
|
|
10
|
+
# Create a file called ".env" in the same folder as your scripts.
|
|
11
|
+
# Add this line (replace with your real key):
|
|
12
|
+
#
|
|
13
|
+
# OPENAI_API_KEY=sk-proj-xxxxxxxxxxxxxxxxxxxxxxxx
|
|
14
|
+
#
|
|
15
|
+
# Optional (only if you have Azure):
|
|
16
|
+
# AZURE_AI_PROJECT_ENDPOINT=https://your-endpoint.api.azureml.ms
|
|
17
|
+
#
|
|
18
|
+
# Then run: bash setup.sh
|
|
19
|
+
# ─────────────────────────────────────────────────────────────────
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
# ─────────────────────────────────────────────────────────────────
|
|
23
|
+
# DECISION TREE: Which script to use?
|
|
24
|
+
# ─────────────────────────────────────────────────────────────────
|
|
25
|
+
#
|
|
26
|
+
# Task says "build a chatbot" or "multi-turn conversation"
|
|
27
|
+
# └── Use: plain_openai/1_multiturn_chat.py
|
|
28
|
+
#
|
|
29
|
+
# Task says "agent with tools" or "function calling" or "agent that can look up data"
|
|
30
|
+
# └── Use: plain_openai/2_simple_agent_tools.py
|
|
31
|
+
#
|
|
32
|
+
# Task says "AutoGen" or "multi-agent" or "two agents talking to each other"
|
|
33
|
+
# └── Basic two agents: autogen/3_autogen_two_agent.py
|
|
34
|
+
# └── With tools: autogen/4_autogen_tool_use.py
|
|
35
|
+
#
|
|
36
|
+
# Task says "Semantic Kernel" or "SK" or "workflow pipeline"
|
|
37
|
+
# └── Basic agent: semantic_kernel/5_sk_basic_agent.py
|
|
38
|
+
# └── Multi-step workflow: semantic_kernel/6_sk_workflow.py
|
|
39
|
+
#
|
|
40
|
+
# Task says "Azure AI Agent" or "Azure AI Foundry" or "thread-based agent"
|
|
41
|
+
# └── Use: azure_ai_agent/7_azure_agent_thread.py
|
|
42
|
+
# └── (Automatically falls back to plain OpenAI if no Azure endpoint)
|
|
43
|
+
# ─────────────────────────────────────────────────────────────────
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
# ─────────────────────────────────────────────────────────────────
|
|
47
|
+
# COMMON CUSTOMIZATIONS — how to adapt any script
|
|
48
|
+
# ─────────────────────────────────────────────────────────────────
|
|
49
|
+
|
|
50
|
+
# 1. CHANGE THE PERSONA / SYSTEM PROMPT
|
|
51
|
+
# Find this line and edit the text:
|
|
52
|
+
# system_message = "You are a helpful assistant..."
|
|
53
|
+
# Example: "You are a customer service agent for Acme Corp. Be polite and concise."
|
|
54
|
+
|
|
55
|
+
# 2. ADD A NEW TOOL (scripts 2 and 4)
|
|
56
|
+
# a) Write a Python function that does the work
|
|
57
|
+
# b) Add it to the TOOLS list (JSON schema) with name + description + parameters
|
|
58
|
+
# c) Add it to TOOL_MAP so it gets called: TOOL_MAP["your_tool_name"] = your_function
|
|
59
|
+
|
|
60
|
+
# 3. CHANGE THE MODEL
|
|
61
|
+
# Find MODEL = "gpt-4o" and change to:
|
|
62
|
+
# "gpt-4-turbo" → cheaper, slightly older
|
|
63
|
+
# "gpt-3.5-turbo" → cheapest, less capable
|
|
64
|
+
# "gpt-4o-mini" → fast and cheap
|
|
65
|
+
|
|
66
|
+
# 4. CHANGE HOW MANY TURNS BEFORE AUTO-STOP (AutoGen scripts)
|
|
67
|
+
# Find: max_consecutive_auto_reply=5
|
|
68
|
+
# Increase to 10 or 15 for longer tasks
|
|
69
|
+
|
|
70
|
+
# 5. MAKE THE AGENT STOP AUTOMATICALLY
|
|
71
|
+
# In AutoGen: the agent sends "TERMINATE" and UserProxy stops
|
|
72
|
+
# In plain OpenAI: add a check: if "DONE" in response: break
|
|
73
|
+
# ─────────────────────────────────────────────────────────────────
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
# ─────────────────────────────────────────────────────────────────
|
|
77
|
+
# PACKAGE INSTALL CHEAT SHEET (if setup.sh didn't work)
|
|
78
|
+
# ─────────────────────────────────────────────────────────────────
|
|
79
|
+
#
|
|
80
|
+
# pip install openai python-dotenv # always needed
|
|
81
|
+
# pip install pyautogen # for AutoGen scripts
|
|
82
|
+
# pip install semantic-kernel # for SK scripts
|
|
83
|
+
# pip install azure-ai-projects azure-identity # for Azure script
|
|
84
|
+
# ─────────────────────────────────────────────────────────────────
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
# ─────────────────────────────────────────────────────────────────
|
|
88
|
+
# CORE PATTERNS TO REMEMBER
|
|
89
|
+
# ─────────────────────────────────────────────────────────────────
|
|
90
|
+
|
|
91
|
+
# MULTI-TURN MEMORY (plain OpenAI) — always append both sides:
|
|
92
|
+
#
|
|
93
|
+
# messages.append({"role": "user", "content": user_input})
|
|
94
|
+
# response = client.chat.completions.create(model=..., messages=messages)
|
|
95
|
+
# reply = response.choices[0].message.content
|
|
96
|
+
# messages.append({"role": "assistant", "content": reply})
|
|
97
|
+
|
|
98
|
+
# TOOL CALL FLOW (plain OpenAI):
|
|
99
|
+
#
|
|
100
|
+
# 1. response = client.chat.completions.create(..., tools=TOOLS, tool_choice="auto")
|
|
101
|
+
# 2. if response.choices[0].finish_reason == "tool_calls":
|
|
102
|
+
# 3. for each tool_call: run the Python function, append result with role="tool"
|
|
103
|
+
# 4. Call the API again → model produces final answer
|
|
104
|
+
|
|
105
|
+
# AUTOGEN PATTERN:
|
|
106
|
+
#
|
|
107
|
+
# assistant = AssistantAgent(name=..., llm_config=..., system_message=...)
|
|
108
|
+
# user_proxy = UserProxyAgent(name=..., human_input_mode="NEVER", ...)
|
|
109
|
+
# user_proxy.initiate_chat(assistant, message="Your task here")
|
|
110
|
+
|
|
111
|
+
# SEMANTIC KERNEL PATTERN:
|
|
112
|
+
#
|
|
113
|
+
# kernel = Kernel()
|
|
114
|
+
# kernel.add_service(OpenAIChatCompletion(...))
|
|
115
|
+
# kernel.add_plugin(MyPlugin(), plugin_name="myplugin")
|
|
116
|
+
# result = await kernel.invoke(kernel.plugins["myplugin"]["function_name"], args)
|
|
117
|
+
# ─────────────────────────────────────────────────────────────────
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
# ─────────────────────────────────────────────────────────────────
|
|
121
|
+
# TROUBLESHOOTING
|
|
122
|
+
# ─────────────────────────────────────────────────────────────────
|
|
123
|
+
#
|
|
124
|
+
# Error: "No module named openai"
|
|
125
|
+
# → Run: pip install openai
|
|
126
|
+
#
|
|
127
|
+
# Error: "AuthenticationError" or "Invalid API key"
|
|
128
|
+
# → Check your .env file has OPENAI_API_KEY=sk-... (no quotes around the key)
|
|
129
|
+
#
|
|
130
|
+
# Error: "No module named autogen"
|
|
131
|
+
# → Run: pip install pyautogen
|
|
132
|
+
#
|
|
133
|
+
# Error: "No module named semantic_kernel"
|
|
134
|
+
# → Run: pip install semantic-kernel
|
|
135
|
+
#
|
|
136
|
+
# Script hangs / no output
|
|
137
|
+
# → API call is waiting. Check internet connectivity to api.openai.com
|
|
138
|
+
# → Try: curl https://api.openai.com/v1/models -H "Authorization: Bearer YOUR_KEY"
|
|
139
|
+
#
|
|
140
|
+
# AutoGen keeps going forever
|
|
141
|
+
# → Add TERMINATE to the assistant's system_message, or reduce max_consecutive_auto_reply
|
|
142
|
+
# ─────────────────────────────────────────────────────────────────
|
|
File without changes
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"""
|
|
2
|
+
SCRIPT 3: AutoGen — Two-Agent Conversation
|
|
3
|
+
==========================================
|
|
4
|
+
What it does:
|
|
5
|
+
- Creates two agents: a UserProxy (acts as the human) and an AssistantAgent (the AI)
|
|
6
|
+
- They converse with each other to complete a task
|
|
7
|
+
- You just give the initial task — agents handle the back-and-forth
|
|
8
|
+
|
|
9
|
+
When to use this pattern:
|
|
10
|
+
- Task automation where you want AI to propose a plan and execute it
|
|
11
|
+
- Any scenario requiring back-and-forth reasoning
|
|
12
|
+
|
|
13
|
+
Key concepts:
|
|
14
|
+
- UserProxyAgent : represents the human / initiates conversation / can run code
|
|
15
|
+
- AssistantAgent : the AI brain that responds and plans
|
|
16
|
+
- initiate_chat() : kicks off the multi-turn conversation between them
|
|
17
|
+
- max_consecutive_auto_reply : how many auto-replies before pausing for human input
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
import os
|
|
21
|
+
from dotenv import load_dotenv
|
|
22
|
+
import autogen
|
|
23
|
+
|
|
24
|
+
load_dotenv()
|
|
25
|
+
|
|
26
|
+
# ── Config: tell AutoGen which LLM to use ───────────────────
|
|
27
|
+
LLM_CONFIG = {
|
|
28
|
+
"config_list": [
|
|
29
|
+
{
|
|
30
|
+
"model": "gpt-4o",
|
|
31
|
+
"api_key": os.getenv("OPENAI_API_KEY"),
|
|
32
|
+
}
|
|
33
|
+
],
|
|
34
|
+
"temperature": 0.7,
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
# ── Create the two agents ────────────────────────────────────
|
|
38
|
+
|
|
39
|
+
# AssistantAgent: the AI that thinks, plans, writes code, answers
|
|
40
|
+
assistant = autogen.AssistantAgent(
|
|
41
|
+
name="Assistant",
|
|
42
|
+
llm_config=LLM_CONFIG,
|
|
43
|
+
system_message="""
|
|
44
|
+
You are a helpful AI assistant.
|
|
45
|
+
When given a task, break it down into clear steps and complete it.
|
|
46
|
+
When you have fully answered, end your message with: TERMINATE
|
|
47
|
+
"""
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
# UserProxyAgent: acts as the human side
|
|
51
|
+
# human_input_mode="NEVER" means it runs fully automatically (no pause for you to type)
|
|
52
|
+
# human_input_mode="TERMINATE" means it runs automatically but stops on TERMINATE keyword
|
|
53
|
+
# human_input_mode="ALWAYS" means it asks for human input at every step
|
|
54
|
+
user_proxy = autogen.UserProxyAgent(
|
|
55
|
+
name="UserProxy",
|
|
56
|
+
human_input_mode="NEVER", # change to "TERMINATE" to review before ending
|
|
57
|
+
max_consecutive_auto_reply=5, # stop after 5 auto-replies max
|
|
58
|
+
is_termination_msg=lambda msg: "TERMINATE" in msg.get("content", ""),
|
|
59
|
+
code_execution_config={"use_docker": False}, # run code locally, not in Docker
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
# ── Run the conversation ─────────────────────────────────────
|
|
63
|
+
if __name__ == "__main__":
|
|
64
|
+
task = """
|
|
65
|
+
I need a summary of the benefits of multi-agent AI systems.
|
|
66
|
+
List 5 key advantages with a one-sentence explanation for each.
|
|
67
|
+
"""
|
|
68
|
+
|
|
69
|
+
print("Starting AutoGen two-agent conversation...\n")
|
|
70
|
+
print("=" * 60)
|
|
71
|
+
|
|
72
|
+
user_proxy.initiate_chat(
|
|
73
|
+
recipient=assistant,
|
|
74
|
+
message=task
|
|
75
|
+
)
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"""
|
|
2
|
+
SCRIPT 4: AutoGen — Agent with Tool Use (Function Registration)
|
|
3
|
+
===============================================================
|
|
4
|
+
What it does:
|
|
5
|
+
- Registers Python functions as tools an AutoGen agent can call
|
|
6
|
+
- The AssistantAgent decides when to invoke the tool
|
|
7
|
+
- UserProxy actually executes the tool and returns the result
|
|
8
|
+
- Models a realistic workflow agent
|
|
9
|
+
|
|
10
|
+
When to use this pattern:
|
|
11
|
+
- Workflow automation agent that needs to call services, APIs, or run logic
|
|
12
|
+
- Research agent, data processing agent, etc.
|
|
13
|
+
|
|
14
|
+
Key concepts:
|
|
15
|
+
- @user_proxy.register_for_execution() : marks the Python function as executable
|
|
16
|
+
- @assistant.register_for_llm() : tells the LLM this tool is available
|
|
17
|
+
- The decorator pattern links definition → LLM awareness → execution
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
import os
|
|
21
|
+
import json
|
|
22
|
+
import autogen
|
|
23
|
+
from autogen import AssistantAgent, UserProxyAgent
|
|
24
|
+
from dotenv import load_dotenv
|
|
25
|
+
|
|
26
|
+
load_dotenv()
|
|
27
|
+
|
|
28
|
+
LLM_CONFIG = {
|
|
29
|
+
"config_list": [
|
|
30
|
+
{
|
|
31
|
+
"model": "gpt-4o",
|
|
32
|
+
"api_key": os.getenv("OPENAI_API_KEY"),
|
|
33
|
+
}
|
|
34
|
+
]
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
# ── Create agents ────────────────────────────────────────────
|
|
38
|
+
assistant = AssistantAgent(
|
|
39
|
+
name="ToolAssistant",
|
|
40
|
+
llm_config=LLM_CONFIG,
|
|
41
|
+
system_message="""
|
|
42
|
+
You are a helpful assistant with access to tools.
|
|
43
|
+
Use the tools when you need to fetch data or do calculations.
|
|
44
|
+
Once you have all the information needed, provide a clear final answer.
|
|
45
|
+
End with TERMINATE when the task is complete.
|
|
46
|
+
"""
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
user_proxy = UserProxyAgent(
|
|
50
|
+
name="UserProxy",
|
|
51
|
+
human_input_mode="NEVER",
|
|
52
|
+
max_consecutive_auto_reply=5,
|
|
53
|
+
is_termination_msg=lambda msg: "TERMINATE" in msg.get("content", ""),
|
|
54
|
+
code_execution_config=False, # we're using registered tools, not raw code execution
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
# ── Define and register tools ────────────────────────────────
|
|
59
|
+
# The decorator pattern: one decorator tells the LLM, one handles execution
|
|
60
|
+
|
|
61
|
+
@user_proxy.register_for_execution() # UserProxy runs this
|
|
62
|
+
@assistant.register_for_llm(
|
|
63
|
+
name="get_stock_price",
|
|
64
|
+
description="Get the current stock price for a given ticker symbol"
|
|
65
|
+
)
|
|
66
|
+
def get_stock_price(ticker: str) -> str:
|
|
67
|
+
"""Simulated stock price lookup."""
|
|
68
|
+
fake_prices = {
|
|
69
|
+
"MSFT": "$415.23",
|
|
70
|
+
"AAPL": "$189.50",
|
|
71
|
+
"GOOGL": "$175.80",
|
|
72
|
+
"OPENAI": "Private company, no public price"
|
|
73
|
+
}
|
|
74
|
+
return fake_prices.get(ticker.upper(), f"Ticker '{ticker}' not found")
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
@user_proxy.register_for_execution()
|
|
78
|
+
@assistant.register_for_llm(
|
|
79
|
+
name="get_company_info",
|
|
80
|
+
description="Get basic information about a company given its name or ticker"
|
|
81
|
+
)
|
|
82
|
+
def get_company_info(company: str) -> str:
|
|
83
|
+
"""Simulated company info lookup."""
|
|
84
|
+
info = {
|
|
85
|
+
"MSFT": "Microsoft Corporation. Founded 1975. CEO: Satya Nadella. Sector: Technology.",
|
|
86
|
+
"AAPL": "Apple Inc. Founded 1976. CEO: Tim Cook. Sector: Technology/Consumer Electronics.",
|
|
87
|
+
"GOOGL": "Alphabet Inc. Founded 1998. CEO: Sundar Pichai. Sector: Technology/Advertising.",
|
|
88
|
+
}
|
|
89
|
+
return info.get(company.upper(), f"No information found for '{company}'")
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
# ── Run the agent with a task that requires tool use ─────────
|
|
93
|
+
if __name__ == "__main__":
|
|
94
|
+
task = """
|
|
95
|
+
I'm researching tech stocks.
|
|
96
|
+
Please get the current price and company info for Microsoft (MSFT) and Apple (AAPL),
|
|
97
|
+
then give me a brief comparison of the two companies.
|
|
98
|
+
"""
|
|
99
|
+
|
|
100
|
+
print("Starting AutoGen Tool-Use Agent...\n")
|
|
101
|
+
print("=" * 60)
|
|
102
|
+
|
|
103
|
+
user_proxy.initiate_chat(
|
|
104
|
+
recipient=assistant,
|
|
105
|
+
message=task
|
|
106
|
+
)
|
|
File without changes
|