-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAgent.java
More file actions
65 lines (55 loc) · 2.31 KB
/
Agent.java
File metadata and controls
65 lines (55 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
* Report API agent — Java example.
*
* Fetches an intent by ID, generates a financial report, and resumes with result.
*
* Usage:
* export AXME_API_KEY="<agent-key>"
* javac -cp axme-sdk.jar Agent.java
* java -cp .:axme-sdk.jar Agent <intent_id>
*/
import dev.axme.sdk.AxmeClient;
import dev.axme.sdk.AxmeClientConfig;
import dev.axme.sdk.RequestOptions;
import java.time.Instant;
import java.util.Map;
public class Agent {
public static void main(String[] args) throws Exception {
if (args.length < 1) {
System.err.println("Usage: java Agent <intent_id>");
System.exit(1);
}
String apiKey = System.getenv("AXME_API_KEY");
if (apiKey == null || apiKey.isEmpty()) {
System.err.println("Error: AXME_API_KEY not set.");
System.exit(1);
}
String intentId = args[0];
var client = new AxmeClient(AxmeClientConfig.forCloud(apiKey));
System.out.println("Processing intent: " + intentId);
var intentData = client.getIntent(intentId, new RequestOptions());
@SuppressWarnings("unchecked")
var intent = (Map<String, Object>) intentData.getOrDefault("intent", intentData);
@SuppressWarnings("unchecked")
var payload = (Map<String, Object>) intent.getOrDefault("payload", Map.of());
if (payload.containsKey("parent_payload")) {
@SuppressWarnings("unchecked")
var pp = (Map<String, Object>) payload.get("parent_payload");
payload = pp;
}
String reportType = (String) payload.getOrDefault("report_type", "unknown");
String fmt = (String) payload.getOrDefault("format", "pdf");
String year = (String) payload.getOrDefault("fiscal_year", "2025");
System.out.println(" Generating " + reportType + " report (" + fmt + ") for FY" + year + "...");
Thread.sleep(2000);
String reportUrl = "https://reports.example.com/FY" + year + "-" + reportType + "." + fmt;
var result = Map.<String, Object>of(
"action", "complete",
"report_url", reportUrl,
"pages", 128,
"generated_at", Instant.now().toString()
);
client.resumeIntent(intentId, result, new RequestOptions());
System.out.println(" Report ready: " + reportUrl);
}
}