@agentvoy/core 0.1.0 ā 0.3.0
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.
- package/dist/adapters/anthropic.d.ts +8 -0
- package/dist/adapters/anthropic.d.ts.map +1 -0
- package/dist/adapters/anthropic.js +250 -0
- package/dist/adapters/anthropic.js.map +1 -0
- package/dist/adapters/crewai.js +10 -2
- package/dist/adapters/crewai.js.map +1 -1
- package/dist/adapters/google-adk.js +1 -0
- package/dist/adapters/google-adk.js.map +1 -1
- package/dist/adapters/index.js +4 -0
- package/dist/adapters/index.js.map +1 -1
- package/dist/adapters/langgraph.d.ts +8 -0
- package/dist/adapters/langgraph.d.ts.map +1 -0
- package/dist/adapters/langgraph.js +317 -0
- package/dist/adapters/langgraph.js.map +1 -0
- package/dist/adapters/openai.js +20 -8
- package/dist/adapters/openai.js.map +1 -1
- package/package.json +1 -1
- package/src/adapters/anthropic.ts +271 -0
- package/src/adapters/crewai.ts +10 -2
- package/src/adapters/google-adk.ts +1 -0
- package/src/adapters/index.ts +4 -0
- package/src/adapters/langgraph.ts +344 -0
- package/src/adapters/openai.ts +20 -8
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"langgraph.js","sourceRoot":"","sources":["../../src/adapters/langgraph.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAUH,4CAAqD;AAExC,QAAA,gBAAgB,GAAqB;IAChD,IAAI,EAAE,WAAW;IACjB,WAAW,EAAE,WAAW;IACxB,QAAQ,EAAE,QAAQ;IAElB,KAAK,CAAC,QAAQ,CAAC,MAAsB;QACnC,MAAM,KAAK,GAAoB;YAC7B;gBACE,IAAI,EAAE,UAAU;gBAChB,OAAO,EAAE,iBAAiB,CAAC,MAAM,CAAC;aACnC;YACD;gBACE,IAAI,EAAE,UAAU;gBAChB,OAAO,EAAE,iBAAiB,EAAE;aAC7B;YACD;gBACE,IAAI,EAAE,UAAU;gBAChB,OAAO,EAAE,iBAAiB,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AAC,KAAK,IAAI,QAAQ,CAAC;IAC7C,MAAM,aAAa,GAAG,MAAM,CAAC,UAAU,EAAE,QAAQ,EAAE,cAAc,IAAI,EAAE,CAAC;IACxE,MAAM,SAAS,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC;IACvC,MAAM,QAAQ,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC;IAErC,OAAO;EACP,MAAM,CAAC,WAAW;;;;;;;;;EASlB,SAAS;;;;;;;;;YASC,QAAQ,WAAW,KAAK;;;;;;;;;;;;;;;;0BAgBV,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2CtC,CAAC;AACF,CAAC;AAED,SAAS,iBAAiB,CAAC,OAAuB;IAChD,OAAO;;;;;;;;;;;;;CAaR,CAAC;AACF,CAAC;AAED,SAAS,iBAAiB;IACxB,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA0CR,CAAC;AACF,CAAC;AAED,SAAS,eAAe,CAAC,MAAsB;IAC7C,OAAO;UACC,MAAM,CAAC,WAAW;;;;;;;;;;;;;mBAaT,MAAM,CAAC,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2BpC,CAAC;AACF,CAAC;AAED,SAAS,oBAAoB,CAAC,MAAsB;IAClD,MAAM,YAAY,GAAG,mBAAmB,CAAC,MAAM,CAAC,CAAC;IACjD,OAAO;;;EAGP,YAAY;;;CAGb,CAAC;AACF,CAAC;AAED,SAAS,kBAAkB,CAAC,MAAsB;IAChD,MAAM,MAAM,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC;IACpC,OAAO,GAAG,MAAM,sBAAsB,CAAC;AACzC,CAAC"}
|
package/dist/adapters/openai.js
CHANGED
|
@@ -104,14 +104,25 @@ Follow these guidelines:
|
|
|
104
104
|
|
|
105
105
|
|
|
106
106
|
async def run_agent(prompt: str) -> str:
|
|
107
|
-
"""Run the agent with the given prompt."""
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
107
|
+
"""Run the agent with the given prompt, enforcing agent.guard.yml at runtime."""
|
|
108
|
+
from agentvoy_guard import Guard
|
|
109
|
+
guard = Guard.from_config()
|
|
110
|
+
|
|
111
|
+
with guard.session() as session:
|
|
112
|
+
session.check_input(prompt)
|
|
113
|
+
|
|
114
|
+
agent = create_agent()
|
|
115
|
+
result = await Runner.run(
|
|
116
|
+
agent,
|
|
117
|
+
prompt,
|
|
118
|
+
max_turns=${maxTurns},
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
final = result.final_output or ""
|
|
122
|
+
session.check_output(final)
|
|
123
|
+
|
|
124
|
+
print(f"[guard] {guard.last_summary}")
|
|
125
|
+
return final
|
|
115
126
|
`;
|
|
116
127
|
}
|
|
117
128
|
function generateToolsFile(_config) {
|
|
@@ -188,6 +199,7 @@ if __name__ == "__main__":
|
|
|
188
199
|
function generateRequirements() {
|
|
189
200
|
return `openai-agents>=0.1.0
|
|
190
201
|
python-dotenv>=1.0.0
|
|
202
|
+
agentvoy-guard>=0.1.0
|
|
191
203
|
`;
|
|
192
204
|
}
|
|
193
205
|
//# sourceMappingURL=openai.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openai.js","sourceRoot":"","sources":["../../src/adapters/openai.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAUH,4CAAqD;AAExC,QAAA,aAAa,GAAqB;IAC7C,IAAI,EAAE,QAAQ;IACd,WAAW,EAAE,mBAAmB;IAChC,QAAQ,EAAE,QAAQ;IAElB,KAAK,CAAC,QAAQ,CAAC,MAAsB;QACnC,MAAM,KAAK,GAAoB;YAC7B;gBACE,IAAI,EAAE,UAAU;gBAChB,OAAO,EAAE,iBAAiB,CAAC,MAAM,CAAC;aACnC;YACD;gBACE,IAAI,EAAE,UAAU;gBAChB,OAAO,EAAE,iBAAiB,CAAC,MAAM,CAAC;aACnC;YACD;gB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oB;IAC3B,OAAO;;;CAGR,CAAC;AACF,CAAC"}
|
package/package.json
CHANGED
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Anthropic SDK Adapter
|
|
3
|
+
*
|
|
4
|
+
* Scaffolds projects using the Anthropic Agent SDK (Python).
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type {
|
|
8
|
+
FrameworkAdapter,
|
|
9
|
+
ScaffoldConfig,
|
|
10
|
+
ScaffoldResult,
|
|
11
|
+
AgentGuardConfig,
|
|
12
|
+
ValidationResult,
|
|
13
|
+
GeneratedFile,
|
|
14
|
+
} from "../types.js";
|
|
15
|
+
import { generateDefaultConfig } from "../config.js";
|
|
16
|
+
|
|
17
|
+
export const anthropicAdapter: FrameworkAdapter = {
|
|
18
|
+
name: "anthropic",
|
|
19
|
+
displayName: "Anthropic SDK",
|
|
20
|
+
language: "python",
|
|
21
|
+
|
|
22
|
+
async scaffold(config: ScaffoldConfig): Promise<ScaffoldResult> {
|
|
23
|
+
const files: GeneratedFile[] = [
|
|
24
|
+
{
|
|
25
|
+
path: "agent.py",
|
|
26
|
+
content: generateAgentFile(config),
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
path: "tools.py",
|
|
30
|
+
content: generateToolsFile(config),
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
path: "run.py",
|
|
34
|
+
content: generateRunFile(config),
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
path: "requirements.txt",
|
|
38
|
+
content: generateRequirements(),
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
path: ".env.example",
|
|
42
|
+
content: "ANTHROPIC_API_KEY=your-api-key-here\n",
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
path: "agent.guard.yml",
|
|
46
|
+
content: generateDefaultConfig(
|
|
47
|
+
config.projectName,
|
|
48
|
+
"anthropic",
|
|
49
|
+
config.model.model || "claude-sonnet-4-20250514"
|
|
50
|
+
),
|
|
51
|
+
},
|
|
52
|
+
];
|
|
53
|
+
|
|
54
|
+
return {
|
|
55
|
+
files,
|
|
56
|
+
dependencies: {},
|
|
57
|
+
devDependencies: {},
|
|
58
|
+
scripts: {
|
|
59
|
+
start: "python run.py",
|
|
60
|
+
},
|
|
61
|
+
postInstallInstructions: [
|
|
62
|
+
"pip install -r requirements.txt",
|
|
63
|
+
"cp .env.example .env",
|
|
64
|
+
"Add your ANTHROPIC_API_KEY to .env",
|
|
65
|
+
"python run.py",
|
|
66
|
+
],
|
|
67
|
+
};
|
|
68
|
+
},
|
|
69
|
+
|
|
70
|
+
validateConfig(config: AgentGuardConfig): ValidationResult {
|
|
71
|
+
const errors: { field: string; message: string }[] = [];
|
|
72
|
+
const warnings: { field: string; message: string }[] = [];
|
|
73
|
+
|
|
74
|
+
if (config.model.provider !== "anthropic") {
|
|
75
|
+
warnings.push({
|
|
76
|
+
field: "model.provider",
|
|
77
|
+
message: `Anthropic adapter works best with provider "anthropic", got "${config.model.provider}"`,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return { valid: errors.length === 0, errors, warnings };
|
|
82
|
+
},
|
|
83
|
+
|
|
84
|
+
getDependencies() {
|
|
85
|
+
return {
|
|
86
|
+
anthropic: ">=0.40.0",
|
|
87
|
+
"python-dotenv": ">=1.0.0",
|
|
88
|
+
};
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
function generateAgentFile(config: ScaffoldConfig): string {
|
|
93
|
+
const model = config.model.model || "claude-sonnet-4-20250514";
|
|
94
|
+
const maxIterations = config.guardrails?.behavior?.max_iterations || 20;
|
|
95
|
+
|
|
96
|
+
return `"""
|
|
97
|
+
${config.projectName} ā Built with AgentVoy
|
|
98
|
+
https://github.com/agentvoy
|
|
99
|
+
"""
|
|
100
|
+
|
|
101
|
+
import anthropic
|
|
102
|
+
from tools import get_tools, process_tool_call
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def create_client() -> anthropic.Anthropic:
|
|
106
|
+
"""Create the Anthropic client."""
|
|
107
|
+
return anthropic.Anthropic()
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def run_agent(prompt: str) -> str:
|
|
111
|
+
"""Run the agent with an agentic loop, enforcing agent.guard.yml at runtime."""
|
|
112
|
+
from agentvoy_guard import Guard
|
|
113
|
+
guard = Guard.from_config()
|
|
114
|
+
|
|
115
|
+
client = create_client()
|
|
116
|
+
tools = get_tools()
|
|
117
|
+
messages = [{"role": "user", "content": prompt}]
|
|
118
|
+
|
|
119
|
+
with guard.session() as session:
|
|
120
|
+
session.check_input(prompt)
|
|
121
|
+
|
|
122
|
+
while True:
|
|
123
|
+
session.tick()
|
|
124
|
+
|
|
125
|
+
response = client.messages.create(
|
|
126
|
+
model="${model}",
|
|
127
|
+
max_tokens=8096,
|
|
128
|
+
tools=tools,
|
|
129
|
+
messages=messages,
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
session.track_usage(response.usage)
|
|
133
|
+
messages.append({"role": "assistant", "content": response.content})
|
|
134
|
+
|
|
135
|
+
if response.stop_reason == "end_turn":
|
|
136
|
+
for block in response.content:
|
|
137
|
+
if hasattr(block, "text"):
|
|
138
|
+
session.check_output(block.text)
|
|
139
|
+
print(f"[guard] {guard.last_summary}")
|
|
140
|
+
return block.text
|
|
141
|
+
return "Done."
|
|
142
|
+
|
|
143
|
+
if response.stop_reason == "tool_use":
|
|
144
|
+
tool_results = []
|
|
145
|
+
for block in response.content:
|
|
146
|
+
if block.type == "tool_use":
|
|
147
|
+
session.tick_tool()
|
|
148
|
+
result = process_tool_call(block.name, block.input)
|
|
149
|
+
tool_results.append({
|
|
150
|
+
"type": "tool_result",
|
|
151
|
+
"tool_use_id": block.id,
|
|
152
|
+
"content": str(result),
|
|
153
|
+
})
|
|
154
|
+
messages.append({"role": "user", "content": tool_results})
|
|
155
|
+
|
|
156
|
+
return "Max iterations reached."
|
|
157
|
+
`;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function generateToolsFile(_config: ScaffoldConfig): string {
|
|
161
|
+
return `"""
|
|
162
|
+
Agent tools ā add your custom tools here.
|
|
163
|
+
"""
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
def get_tools() -> list:
|
|
167
|
+
"""Return tool definitions for the Anthropic API."""
|
|
168
|
+
return [
|
|
169
|
+
{
|
|
170
|
+
"name": "search_web",
|
|
171
|
+
"description": "Search the web for information on a given topic.",
|
|
172
|
+
"input_schema": {
|
|
173
|
+
"type": "object",
|
|
174
|
+
"properties": {
|
|
175
|
+
"query": {
|
|
176
|
+
"type": "string",
|
|
177
|
+
"description": "The search query.",
|
|
178
|
+
}
|
|
179
|
+
},
|
|
180
|
+
"required": ["query"],
|
|
181
|
+
},
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
"name": "read_file",
|
|
185
|
+
"description": "Read the contents of a file.",
|
|
186
|
+
"input_schema": {
|
|
187
|
+
"type": "object",
|
|
188
|
+
"properties": {
|
|
189
|
+
"path": {
|
|
190
|
+
"type": "string",
|
|
191
|
+
"description": "Path to the file to read.",
|
|
192
|
+
}
|
|
193
|
+
},
|
|
194
|
+
"required": ["path"],
|
|
195
|
+
},
|
|
196
|
+
},
|
|
197
|
+
]
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
def process_tool_call(tool_name: str, tool_input: dict) -> str:
|
|
201
|
+
"""Execute a tool call and return the result."""
|
|
202
|
+
if tool_name == "search_web":
|
|
203
|
+
return _search_web(tool_input["query"])
|
|
204
|
+
elif tool_name == "read_file":
|
|
205
|
+
return _read_file(tool_input["path"])
|
|
206
|
+
else:
|
|
207
|
+
return f"Unknown tool: {tool_name}"
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
def _search_web(query: str) -> str:
|
|
211
|
+
"""Search the web for information."""
|
|
212
|
+
# TODO: Implement your search logic (e.g., Tavily, Serper, Brave Search)
|
|
213
|
+
return f"Search results for: {query}"
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
def _read_file(path: str) -> str:
|
|
217
|
+
"""Read a file's contents."""
|
|
218
|
+
try:
|
|
219
|
+
with open(path, "r") as f:
|
|
220
|
+
return f.read()
|
|
221
|
+
except FileNotFoundError:
|
|
222
|
+
return f"File not found: {path}"
|
|
223
|
+
except PermissionError:
|
|
224
|
+
return f"Permission denied: {path}"
|
|
225
|
+
`;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
function generateRunFile(config: ScaffoldConfig): string {
|
|
229
|
+
return `"""
|
|
230
|
+
Run the ${config.projectName} agent.
|
|
231
|
+
"""
|
|
232
|
+
|
|
233
|
+
from dotenv import load_dotenv
|
|
234
|
+
from agent import run_agent
|
|
235
|
+
|
|
236
|
+
load_dotenv()
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
def main():
|
|
240
|
+
print("\\nš ${config.projectName} ā Powered by AgentVoy")
|
|
241
|
+
print("=" * 50)
|
|
242
|
+
print("Type your prompt (or 'quit' to exit):\\n")
|
|
243
|
+
|
|
244
|
+
while True:
|
|
245
|
+
try:
|
|
246
|
+
prompt = input("> ")
|
|
247
|
+
if prompt.lower() in ("quit", "exit", "q"):
|
|
248
|
+
print("\\nGoodbye!")
|
|
249
|
+
break
|
|
250
|
+
if not prompt.strip():
|
|
251
|
+
continue
|
|
252
|
+
|
|
253
|
+
print("\\nThinking...\\n")
|
|
254
|
+
result = run_agent(prompt)
|
|
255
|
+
print(f"\\n{result}\\n")
|
|
256
|
+
except KeyboardInterrupt:
|
|
257
|
+
print("\\n\\nGoodbye!")
|
|
258
|
+
break
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
if __name__ == "__main__":
|
|
262
|
+
main()
|
|
263
|
+
`;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
function generateRequirements(): string {
|
|
267
|
+
return `anthropic>=0.40.0
|
|
268
|
+
python-dotenv>=1.0.0
|
|
269
|
+
agentvoy-guard>=0.1.0
|
|
270
|
+
`;
|
|
271
|
+
}
|
package/src/adapters/crewai.ts
CHANGED
|
@@ -220,18 +220,25 @@ def main():
|
|
|
220
220
|
print("\\nš ${config.projectName} ā Powered by AgentVoy")
|
|
221
221
|
print("=" * 50)
|
|
222
222
|
|
|
223
|
+
from agentvoy_guard import Guard
|
|
224
|
+
guard = Guard.from_config()
|
|
225
|
+
|
|
223
226
|
topic = input("\\nEnter a topic to research: ")
|
|
224
227
|
if not topic.strip():
|
|
225
228
|
print("No topic provided. Exiting.")
|
|
226
229
|
return
|
|
227
230
|
|
|
228
|
-
|
|
229
|
-
|
|
231
|
+
with guard.session() as session:
|
|
232
|
+
session.check_input(topic)
|
|
233
|
+
crew = create_crew()
|
|
234
|
+
result = crew.kickoff(inputs={"topic": topic})
|
|
235
|
+
session.check_output(str(result))
|
|
230
236
|
|
|
231
237
|
print("\\n" + "=" * 50)
|
|
232
238
|
print("RESULT:")
|
|
233
239
|
print("=" * 50)
|
|
234
240
|
print(result)
|
|
241
|
+
print(f"\\n[guard] {guard.last_summary}")
|
|
235
242
|
|
|
236
243
|
|
|
237
244
|
if __name__ == "__main__":
|
|
@@ -243,6 +250,7 @@ function generateRequirements(): string {
|
|
|
243
250
|
return `crewai>=0.80.0
|
|
244
251
|
crewai-tools>=0.14.0
|
|
245
252
|
python-dotenv>=1.0.0
|
|
253
|
+
agentvoy-guard>=0.1.0
|
|
246
254
|
`;
|
|
247
255
|
}
|
|
248
256
|
|
package/src/adapters/index.ts
CHANGED
|
@@ -10,8 +10,12 @@ import { registerAdapter } from "./registry.js";
|
|
|
10
10
|
import { openaiAdapter } from "./openai.js";
|
|
11
11
|
import { googleAdkAdapter } from "./google-adk.js";
|
|
12
12
|
import { crewaiAdapter } from "./crewai.js";
|
|
13
|
+
import { anthropicAdapter } from "./anthropic.js";
|
|
14
|
+
import { langgraphAdapter } from "./langgraph.js";
|
|
13
15
|
|
|
14
16
|
// Register built-in adapters
|
|
15
17
|
registerAdapter(openaiAdapter);
|
|
16
18
|
registerAdapter(googleAdkAdapter);
|
|
17
19
|
registerAdapter(crewaiAdapter);
|
|
20
|
+
registerAdapter(anthropicAdapter);
|
|
21
|
+
registerAdapter(langgraphAdapter);
|