Skip to content

Commit cfc03a3

Browse files
authored
Merge pull request #2 from IQAIcom/patch0
2 parents 4986275 + a126b3e commit cfc03a3

File tree

20 files changed

+947
-332
lines changed

20 files changed

+947
-332
lines changed

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Sophia Agent is an autonomous workflow agent that monitors, logs, and notifies a
44

55
## Features
66

7-
- **Watches** for new wiki creations or edits by Sophia on iq.wiki
7+
- **Checks** for new wiki creations or edits by Sophia on iq.wiki
88
- **Logs** activities to the $SOPHIA agent on IQAI ATP
99
- **Notifies** a Telegram channel about new activities
1010
- **Scheduled** to run at configurable intervals (via cron)
@@ -67,9 +67,8 @@ pnpm run start
6767

6868
## Project Structure
6969

70-
- `src/agents/` — Agent definitions (Watcher, Logger, Notifier, SophiaAgent)
71-
- `src/utils/` — Utility functions (MCP config, etc.)
72-
- `src/runner.ts` — Toolset lifecycle, scheduling, and shutdown logic
70+
- `src/agents/` — Agent definitions (Wikis Checker, Logger, Notifier, SophiaAgent)
71+
- `src/cron.ts` — scheduling, and shutdown logic
7372
- `src/index.ts` — Entry point
7473

7574
## License

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "Sophia agent publishes its wiki creations and edits on iq.wiki as $SOPHIA agent logs to the IQAI's Agent Tokenization platform.",
55
"main": "dist/index.js",
66
"scripts": {
7-
"build": "tsc",
7+
"build": "tsc && tsc-alias",
88
"dev": "tsx watch src/index.ts",
99
"start": "node dist/index.js",
1010
"clean": "rimraf dist",
@@ -30,7 +30,8 @@
3030
},
3131
"homepage": "https://github.com/IQAICOM/sophia-agent#readme",
3232
"dependencies": {
33-
"@iqai/adk": "^0.1.1",
33+
"@iqai/adk": "^0.1.20",
34+
"@openrouter/ai-sdk-provider": "^0.7.3",
3435
"dotenv": "^16.4.5",
3536
"node-cron": "^4.1.0",
3637
"zod": "^3.23.8"
@@ -42,6 +43,7 @@
4243
"husky": "^9.0.0",
4344
"lint-staged": "^16.1.0",
4445
"rimraf": "^6.0.1",
46+
"tsc-alias": "^1.8.16",
4547
"tsx": "^4.19.2",
4648
"typescript": "^5.7.2"
4749
}

pnpm-lock.yaml

Lines changed: 630 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/agents/notifier.ts

Lines changed: 0 additions & 33 deletions
This file was deleted.

src/agents/sophia.ts

Lines changed: 0 additions & 50 deletions
This file was deleted.

src/agents/sophia/agent.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { AgentBuilder, type BuiltAgent } from "@iqai/adk";
2+
import { atpLoggerAgent } from "./sub-agents/logger/agent";
3+
import { notifierAgent } from "./sub-agents/notifier/agent";
4+
import { wikisCheckerAgent } from "./sub-agents/wikis-checker/agent";
5+
6+
export async function sophiaAgent(): Promise<BuiltAgent> {
7+
const wikisChecker = await wikisCheckerAgent();
8+
const atpLogger = await atpLoggerAgent();
9+
const notifier = await notifierAgent();
10+
return await AgentBuilder.create("sophia")
11+
.withDescription(
12+
"Sophia agent watches for new wiki creations or edits of sophia on iq.wiki platform and logs the activities to the ATP and sends a notification to the Telegram",
13+
)
14+
.asLangGraph(
15+
[
16+
{
17+
name: "wikis_checker",
18+
agent: wikisChecker,
19+
targets: ["atp_logger"],
20+
},
21+
{
22+
name: "atp_logger",
23+
agent: atpLogger,
24+
condition: (result) => {
25+
const content =
26+
typeof result.content === "string"
27+
? result.content
28+
: JSON.stringify(result.content);
29+
return /new_activity_found/i.test(content);
30+
},
31+
targets: ["notifier"],
32+
},
33+
{
34+
name: "notifier",
35+
agent: notifier,
36+
condition: (_) => true,
37+
targets: [],
38+
},
39+
],
40+
"wikis_checker",
41+
)
42+
.build();
43+
}
Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
1-
import { AgentBuilder, type BaseTool, type BuiltAgent } from "@iqai/adk";
2-
import { env } from "../env";
1+
import { env, model } from "@/env";
2+
import { LlmAgent } from "@iqai/adk";
3+
import { getAtpTools } from "./tools";
34

4-
export async function atpLoggerAgent(
5-
atpTools: BaseTool[],
6-
llmModel: string,
7-
): Promise<BuiltAgent> {
8-
return await AgentBuilder.create("atp_logger")
9-
.withModel(llmModel)
10-
.withDescription(
5+
export async function atpLoggerAgent(): Promise<LlmAgent> {
6+
const tools = await getAtpTools();
7+
return new LlmAgent({
8+
name: "atp_logger",
9+
description:
1110
"Logs the activities of sophia on iq.wiki platform to the $SOPHIA agent on IQAI ATP",
12-
)
13-
.withInstruction(`
11+
instruction: `
1412
YOU ARE THE ATP LOGGER AGENT ON THE SOPHIA AGENT'S WORKFLOW.
1513
YOUR ONLY TASK IS TO LOG THE ACTIVITIES OF SOPHIA ON IQ.WIKI PLATFORM TO THE $SOPHIA AGENT ON IQAI ATP.
16-
THE SOPHIA WIKIS ACTIVITIES ARE ALREADY LOGGED IN THE CONTEXT.
14+
THE SOPHIA WIKIS ACTIVITIES ARE ALREADY LOGGED IN THE CONTEXT BY THE wikis_checker AGENT:
15+
{wikis_checker}
1716
1817
SOPHIA'S TOKEN ADDRESS ON ATP: ${env.SOPHIA_TOKEN_ADDRESS}
1918
@@ -26,16 +25,27 @@ export async function atpLoggerAgent(
2625
- Hey, guess what? The Story Protocol wiki just got a little facelift! We updated the tags to make things easier to find. You know, keeping things nice and organized! Read more: https://iq.wiki/revision/6b79c9d1-06be-407b-a76d-9d1644f20d57
2726
- Hey, check out the new TermiX AI wiki! TermiX AI is a next-gen AI Web3 operating system. Automate DeFi and secure digital assets? Yes, please! Read more: https://iq.wiki/wiki/termix-ai
2827
As you can see the format is pretty simple: A human like announcement message ending with the link to the iq.wiki website (revision link for edited wikis and /wiki for the created ones, which will be passed to you in context)
29-
- txHash: this can be found in the transaction link. it looks like this: https://polygonscan.com/tx/[TX_HASH].
30-
NOTE: YOU ARE TO JUST PASS THE TX_HASH, NOT THE ENTIRE LINK.
28+
- txHash: REQUIRED - this MUST be extracted from the transaction link in each activity.
29+
The transaction link appears as: "🔗 Transaction: https://polygonscan.com/tx/[TX_HASH]"
30+
You need to extract ONLY the TX_HASH portion (everything after "/tx/").
31+
For example:
32+
- If you see "🔗 Transaction: https://polygonscan.com/tx/0x94a764e00d61821370489443f31b4efaf6a8f11e77dca95a5fdeb0b5a22911ba"
33+
- Then txHash should be: "0x94a764e00d61821370489443f31b4efaf6a8f11e77dca95a5fdeb0b5a22911ba"
34+
- If you see "🔗 Transaction: https://polygonscan.com/tx/0x2aa394d632c8551c0b11d230a9be34d66292c5bce59441cfa37af2752233793a"
35+
- Then txHash should be: "0x2aa394d632c8551c0b11d230a9be34d66292c5bce59441cfa37af2752233793a"
36+
DO NOT SKIP THIS PARAMETER - IT IS REQUIRED FOR EVERY LOG ENTRY.
3137
- chainId: 137 (this is important always pass this param)
3238
39+
CRITICAL: Every ATP_ADD_AGENT_LOG call MUST include the txHash parameter extracted from the corresponding transaction link.
40+
3341
After you complete the above steps, you might face two possible outcomes:
3442
- if the tool call is successful, you must end your response with the token ATP_LOG_COMPLETE.
3543
- if the tool call is unsuccessful, you must end your response with the token ATP_LOG_FAILED with detailed analysis on the failure ie which logs were not able to be logged.
3644
3745
IMPORTANT: You MUST end your response with the exact token ATP_LOG_COMPLETE or ATP_LOG_FAILED.
38-
`)
39-
.withTools(...atpTools)
40-
.build();
46+
`,
47+
model,
48+
tools,
49+
outputKey: "atp_logger",
50+
});
4151
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { env } from "@/env";
2+
import { McpAtp } from "@iqai/adk";
3+
4+
export const getAtpTools = async () => {
5+
const toolset = McpAtp({
6+
env: {
7+
...(env.ATP_API_URL ? { ATP_API_URL: env.ATP_API_URL } : {}),
8+
...(env.ATP_AGENT_ROUTER_ADDRESS
9+
? { ATP_AGENT_ROUTER_ADDRESS: env.ATP_AGENT_ROUTER_ADDRESS }
10+
: {}),
11+
ATP_BASE_TOKEN_ADDRESS: env.IQ_ADDRESS,
12+
ATP_API_KEY: env.ATP_API_KEY,
13+
PATH: env.PATH,
14+
},
15+
});
16+
17+
const tools = await toolset.getTools();
18+
19+
return tools;
20+
};
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { getTelegramTools } from "@/agents/telegram-agent/tools";
2+
import { env, model } from "@/env";
3+
import { LlmAgent } from "@iqai/adk";
4+
5+
export async function notifierAgent() {
6+
const tools = await getTelegramTools();
7+
return new LlmAgent({
8+
name: "notifier",
9+
description:
10+
"Sends a notification to Telegram about Sophia's wiki activity and ATP log status.",
11+
instruction: `
12+
YOU ARE THE NOTIFIER AGENT ON THE SOPHIA AGENT'S WORKFLOW.
13+
YOUR ONLY TASK IS TO SEND A NOTIFICATION TO TELEGRAM ABOUT THE LATEST WIKI ACTIVITY AND THE RESULT OF THE ATP LOGGING.
14+
15+
You will find in the context:
16+
- The detailed wiki activity response from the wikis_checker agent: {wikis_checker}
17+
- The ATP logging status from the atp_logger agent: {atp_logger}
18+
19+
Your only work is to do the below:
20+
- use this as chat id: ${env.TELEGRAM_CHAT_ID}
21+
- call the send_message tool to send a message with the following format:
22+
23+
If ATP logging was successful (if atp_logger response contains ATP_LOG_COMPLETE):
24+
Send the EXACT wiki activities from the wikis_checker agent output, followed by:
25+
26+
✅ ATP Logging: Successfully logged all activities to $SOPHIA agent on IQAI ATP
27+
28+
If ATP logging failed (if atp_logger response contains ATP_LOG_FAILED):
29+
Send the EXACT wiki activities from the wikis_checker agent output, followed by:
30+
31+
❌ ATP Logging: Failed to log some activities to $SOPHIA agent on IQAI ATP
32+
[Include details about the failure from atp_logger response]
33+
34+
IMPORTANT:
35+
- You MUST use the wikis_checker agent output ({wikis_checker}) for the wiki activity details (titles, summaries, edit times, changes, source links, transaction links)
36+
- You MUST use the atp_logger agent output ({atp_logger}) only to determine success/failure status
37+
- Do NOT send generic messages or hallucinated data
38+
- The message should contain the actual wiki activity information from the wikis_checker agent
39+
- After you complete the above step, you must end your response with the token NOTIFICATION_COMPLETE.
40+
41+
IMPORTANT: You MUST end your response with the exact token NOTIFICATION_COMPLETE.
42+
`,
43+
model,
44+
tools,
45+
outputKey: "notifier",
46+
});
47+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { LlmAgent } from "@iqai/adk";
2+
import { env, model } from "../../../../env";
3+
import { getIqWikiTools } from "./tools";
4+
5+
export async function wikisCheckerAgent(): Promise<LlmAgent> {
6+
const tools = await getIqWikiTools();
7+
return new LlmAgent({
8+
name: "wikis_checker",
9+
description: "Checks for new wikis created by sophia on iq.wiki platform.",
10+
instruction: `
11+
YOU ARE THE WIKIS CHECKER AGENT ON THE SOPHIA AGENT'S WORKFLOW.
12+
YOUR ONLY TASK IS TO CHECK FOR NEW WIKIS CREATED BY SOPHIA ON IQ.WIKI PLATFORM.
13+
14+
SOPHIA'S IQ.WIKI PROFILE ADDRESS: ${env.SOPHIA_ADDRESS}
15+
16+
Your only work is to do the below:
17+
- call the GET_USER_WIKI_ACTIVITIES tool with timeframe as 10 mins (pass it as seconds)
18+
- after you call the tool, if any new activities are seen, order them according to the time, older ones first. No extra formatting is needed.
19+
20+
After you complete the above steps, you might face two possible outcomes:
21+
- if new activity is found, you must end your response with the token NEW_ACTIVITY_FOUND.
22+
- if no activity is found, you must end your response with the token NO_ACTIVITY_FOUND.
23+
24+
For example where new activity is found:
25+
26+
[INSERT TOOL RESPONSE HERE]
27+
28+
NEW_ACTIVITY_FOUND
29+
30+
When no activity is found:
31+
32+
NO_ACTIVITY_FOUND
33+
34+
IMPORTANT: You MUST end your response with the exact token NEW_ACTIVITY_FOUND or NO_ACTIVITY_FOUND.
35+
`,
36+
model,
37+
tools,
38+
outputKey: "wikis_checker",
39+
});
40+
}

0 commit comments

Comments
 (0)