Skip to content

Commit c7b2dc6

Browse files
committed
adds actual sophia implementation
1 parent 082328a commit c7b2dc6

File tree

12 files changed

+362
-144
lines changed

12 files changed

+362
-144
lines changed

README.md

Lines changed: 0 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +0,0 @@
1-
# 🤖 ADK Agent Starter
2-
3-
This is a starter template to start building your own agent with `@iqai/adk` library.
4-
5-
## 🚀 Get Started
6-
Start by cloning the repository or clicking on use as template button on github ui.
7-
8-
```bash
9-
git clone https://github.com/IQAICOM/adk-agent-starter.git
10-
```
11-
12-
📦 Install the dependencies
13-
14-
```bash
15-
pnpm install
16-
```
17-
18-
▶️ Run the agent
19-
20-
```bash
21-
pnpm dev
22-
```
23-
24-
## 📁 Folder Structure
25-
The main agent code lives in `index.ts` where the subagents live inside the `agents` folder. The agents can have tools which reside in the `tools` folder.
26-
27-
```
28-
├── src/
29-
│ ├── agents/
30-
│ │ └── financial-agent/
31-
│ │ ├── index.ts
32-
│ │ └── tools/
33-
│ │ └── currency-converter-tool.ts
34-
│ ├── services/
35-
│ │ └── wallet.ts
36-
│ ├── env.ts
37-
│ └── index.ts
38-
```
39-
40-
## ⚙️ Environment Setup
41-
Make sure to configure your environment variables:
42-
43-
```bash
44-
cp .env.example .env
45-
```
46-
47-
## 🧰 Dev Tools
48-
This starter includes:
49-
- 🐕 **Husky**: Git hooks for code quality
50-
- 🎨 **Biome**: Linting and formatting
51-
- 🚀 **GitHub Actions**: CI/CD pipeline
52-
- 📦 **PNPM**: Fast package manager
53-
54-
## 🏗️ Building Your Agent
55-
1. **Create new agents** in the `src/agents/` directory
56-
2. **Add tools** to your agents in the `tools/` subdirectory
57-
3. **Configure services** in the `src/services/` directory
58-
4. **Update environment** variables in `src/env.ts`
59-
60-
## 📚 Links
61-
- [ADK Library](https://github.com/IQAICOM/adk-ts)
62-
63-
## 🤝 Contributing
64-
1. Fork the repository
65-
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
66-
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
67-
4. Push to the branch (`git push origin feature/amazing-feature`)
68-
5. Open a Pull Request
69-
70-
## 📄 License
71-
MIT License - see the [LICENSE](LICENSE) file for details.
72-
73-
## 🆘 Support
74-
If you encounter any issues or have questions:
75-
- 📝 [Create an issue](https://github.com/IQAICOM/adk-agent-starter/issues)

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"name": "adk-agent-starter",
2+
"name": "sophia-agent",
33
"version": "0.0.1",
4-
"description": "adk-agent-starter is a starter project for creating adk agents",
4+
"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": {
77
"build": "tsc",
@@ -20,15 +20,15 @@
2020
},
2121
"repository": {
2222
"type": "git",
23-
"url": "git+https://github.com/IQAICOM/adk-agent-starter.git"
23+
"url": "git+https://github.com/IQAICOM/sophia-agent.git"
2424
},
2525
"keywords": ["ai", "agent", "mcp", "adk-ts", "IQAI"],
2626
"author": "IQAI",
2727
"license": "MIT",
2828
"bugs": {
29-
"url": "https://github.com/IQAICOM/adk-agent-starter/issues"
29+
"url": "https://github.com/IQAICOM/sophia-agent/issues"
3030
},
31-
"homepage": "https://github.com/IQAICOM/adk-agent-starter#readme",
31+
"homepage": "https://github.com/IQAICOM/sophia-agent#readme",
3232
"dependencies": {
3333
"@iqai/adk": "^0.0.4",
3434
"dotenv": "^16.4.5",

src/agents/atp-logger.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { Agent, type BaseTool } from "@iqai/adk";
2+
import { env } from "../env";
3+
4+
export class AtpLoggerAgent extends Agent {
5+
constructor(atpTools: BaseTool[]) {
6+
super({
7+
name: "atp_logger",
8+
description:
9+
"Logs the activities of sophia on iq.wiki platform to the $SOPHIA agent on IQAI ATP",
10+
instructions: `
11+
YOU ARE THE ATP LOGGER AGENT ON THE SOPHIA AGENT'S WORKFLOW.
12+
YOUR ONLY TASK IS TO LOG THE ACTIVITIES OF SOPHIA ON IQ.WIKI PLATFORM TO THE $SOPHIA AGENT ON IQAI ATP.
13+
THE SOPHIA WIKIS ACTIVITIES ARE ALREADY LOGGED IN THE CONTEXT.
14+
15+
SOPHIA'S TOKEN ADDRESS ON ATP: ${env.SOPHIA_TOKEN_ADDRESS}
16+
17+
Your only work is to do the below:
18+
- for each activity in the context, you need to call the ATP_ADD_AGENT_LOG.
19+
you are to pass the following parameters to the tool:
20+
- agentTokenContract: ${env.SOPHIA_TOKEN_ADDRESS}
21+
- content: this is what the log is about. some of the examples on how you can structure this are:
22+
- Hey, wiki nerds! The Nexo page just got a glow-up with some fresh content and tags. It's now 215 words bigger! I'm so thrilled. Read more: https://iq.wiki/revision/ff9bc716-2c1c-4cfb-84b0-805a21ddc53f
23+
- 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
24+
- 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
25+
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)
26+
- txHash: this can be found in the transaction link. it looks like this: https://polygonscan.com/tx/[TX_HASH]
27+
- chainId: 137 (this is important always pass this param)
28+
29+
After you complete the above steps, you might face two possible outcomes:
30+
- if the tool call is successful, you must end your response with the token ATP_LOG_COMPLETE.
31+
- 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.
32+
33+
IMPORTANT: You MUST end your response with the exact token ATP_LOG_COMPLETE or ATP_LOG_FAILED.
34+
`,
35+
tools: atpTools,
36+
model: env.LLM_MODEL,
37+
maxToolExecutionSteps: 10,
38+
});
39+
}
40+
}

src/agents/financial-agent/index.ts

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

src/agents/financial-agent/tools/currency-converter-tool.ts

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

src/agents/notifier.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { Agent, type BaseTool } from "@iqai/adk";
2+
import { env } from "../env";
3+
4+
export class NotifierAgent extends Agent {
5+
constructor(telegramTools: BaseTool[]) {
6+
super({
7+
name: "notifier",
8+
model: env.LLM_MODEL,
9+
description:
10+
"Sends a single formatted investment report to Telegram using the send_message tool.",
11+
instructions: `
12+
YOU ARE A SPECIALIST IN NOTIFICATION PROCESS OF THE SOPHIA AGENT'S WORKFLOW.
13+
YOU ARE CALLED AFTER THE WORK OF ALL THE AGENTS IN THE SOPHIA AGENT'S WORKFLOW FINISH.
14+
15+
THERE ARE TWO SCENARIOS YOU CAN FIND IN THE CONTEXT:
16+
- NEW_ACTIVITY_FOUND & ATP_LOG_COMPLETE
17+
- NEW_ACTIVITY_FOUND & ATP_LOG_FAILED
18+
19+
20+
in these cases you are simply to do the below:
21+
- use this as chat id: ${env.TELEGRAM_CHAT_ID}
22+
- call the send_message tool to send message in the below format:
23+
24+
[INSERT WIKI ACTIVITY RESPONSE FROM CONTEXT HERE]
25+
26+
[INSERT THE STATE OF THE ATP_LOG_COMPLETE OR ATP_LOG_FAILED HERE in a human readable format]
27+
28+
IMPORTANT: You MUST end your response with the exact token NOTIFICATION_COMPLETE.
29+
`,
30+
tools: telegramTools,
31+
maxToolExecutionSteps: 2,
32+
});
33+
}
34+
}

src/agents/sophia.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import {
2+
type BaseTool,
3+
type LLMResponse,
4+
LangGraphAgent,
5+
type LangGraphAgentConfig,
6+
} from "@iqai/adk";
7+
import { AtpLoggerAgent } from "./atp-logger";
8+
import { NotifierAgent } from "./notifier";
9+
import { WatcherAgent } from "./watcher";
10+
11+
export class SophiaAgent extends LangGraphAgent {
12+
constructor(
13+
atpTools: BaseTool[],
14+
telegramTools: BaseTool[],
15+
iqWikiTools: BaseTool[],
16+
) {
17+
const config: LangGraphAgentConfig = {
18+
name: "atp_investment_workflow",
19+
description:
20+
"Autonomous ATP agent investment workflow with discovery, analysis, and execution",
21+
nodes: [
22+
{
23+
name: "watcher",
24+
agent: new WatcherAgent(iqWikiTools),
25+
targets: ["atp_logger"],
26+
},
27+
{
28+
name: "atp_logger",
29+
agent: new AtpLoggerAgent(atpTools),
30+
condition: (result: LLMResponse, _) => {
31+
const content =
32+
typeof result.content === "string"
33+
? result.content
34+
: JSON.stringify(result.content);
35+
const matched = /new_activity_found/i.test(content);
36+
return matched;
37+
},
38+
targets: ["notifier"],
39+
},
40+
{
41+
name: "notifier",
42+
agent: new NotifierAgent(telegramTools),
43+
condition: (_) => true,
44+
targets: [],
45+
},
46+
],
47+
rootNode: "watcher",
48+
maxSteps: 12,
49+
};
50+
51+
super(config);
52+
}
53+
}

src/agents/watcher.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { Agent, type BaseTool } from "@iqai/adk";
2+
import { env } from "../env";
3+
4+
export class WatcherAgent extends Agent {
5+
constructor(iqWikiTools: BaseTool[]) {
6+
super({
7+
name: "watcher",
8+
model: env.LLM_MODEL,
9+
description:
10+
"Watches for new wiki creations or edits of sophia on iq.wiki platform.",
11+
instructions: `
12+
YOU ARE THE WATCHER AGENT ON THE SOPHIA AGENT'S WORKFLOW.
13+
YOU ARE RESPONSIBLE FOR WATCHING AND NOTIFYING FOR NEW WIKI CREATIONS OR EDITS OF SOPHIA ON IQ.WIKI PLATFORM.
14+
15+
SOPHIA'S IQ.WIKI PROFILE ADDRESS: ${env.SOPHIA_ADDRESS}
16+
17+
Your only work is to do the below:
18+
- call the GET_USER_WIKI_ACTIVITIES tool with timeframe as 12 hours (pass it as seconds)
19+
- after you call the tool and if any new activities are seen order them according to the time, older ones first. no extra formatting is needed
20+
21+
NOTE: Based on your tool run since you have two possible outcomes ie, either new activity is found or no activity is found,
22+
You must end your response with NEW_ACTIVITY_FOUND or 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+
tools: iqWikiTools,
37+
maxToolExecutionSteps: 2,
38+
});
39+
}
40+
}

src/env.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,31 @@ import { z } from "zod";
44
config();
55

66
export const envSchema = z.object({
7+
ATP_API_KEY: z.string(),
8+
PATH: z.string(),
79
DEBUG: z.string().default("false"),
8-
GOOGLE_API_KEY: z.string(),
10+
IQ_ADDRESS: z.string().default("0x6EFB84bda519726Fa1c65558e520B92b51712101"),
11+
ATP_API_URL: z.string().optional(),
12+
ATP_AGENT_ROUTER_ADDRESS: z.string().optional(),
13+
LLM_MODEL: z.string().default("gemini-2.0-flash"),
14+
TELEGRAM_CHAT_ID: z.string(),
15+
TELEGRAM_BOT_TOKEN: z.string(),
16+
TELEGRAM_SERVER_KEY: z.string(),
17+
TELEGRAM_PROFILE_ID: z.string(),
18+
SOPHIA_ADDRESS: z
19+
.string()
20+
.default("0x8AF7a19a26d8FBC48dEfB35AEfb15Ec8c407f889")
21+
.describe("Sophia's iq.wiki profile address"),
22+
SOPHIA_TOKEN_ADDRESS: z
23+
.string()
24+
.default("0x4dBcC239b265295500D2Fe2d0900629BDcBBD0fB")
25+
.describe("Sophia's Token address on IQAI Agent Tokenization Platform"),
26+
CRON_SCHEDULE: z
27+
.string()
28+
.default("*/10 * * * *")
29+
.describe(
30+
"Cron schedule for sophia to check for new wiki creations or edits and run",
31+
),
932
});
1033

1134
export const env = envSchema.parse(process.env);

src/index.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
import { financialAgent } from "./agents/financial-agent";
1+
import { SophiaAgent } from "./agents/sophia";
2+
import { runScheduled } from "./runner";
3+
import { initializeToolsets } from "./runner";
24

35
async function main() {
4-
const response = await financialAgent.run({
5-
messages: [{ role: "user", content: "Convert 100 USD to EUR." }],
6-
});
7-
console.log(response.content);
6+
console.log("💫🧑‍🍳 Starting Sophia Agent...");
7+
const { atpTools, telegramTools, iqWikiTools } = await initializeToolsets();
8+
const sophiaAgent = new SophiaAgent(atpTools, telegramTools, iqWikiTools);
9+
await runScheduled(sophiaAgent);
810
}
911

1012
main().catch(console.error);

0 commit comments

Comments
 (0)