Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into tcm-contributor-page
Browse files Browse the repository at this point in the history
  • Loading branch information
madjin committed Dec 12, 2024
2 parents 78e5c57 + c411c2f commit bedb291
Show file tree
Hide file tree
Showing 30 changed files with 1,966 additions and 669 deletions.
6 changes: 6 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ TWITTER_EMAIL= # Account email
TWITTER_2FA_SECRET=
TWITTER_COOKIES= # Account cookies
TWITTER_POLL_INTERVAL=120 # How often (in seconds) the bot should check for interactions
TWITTER_SEARCH_ENABLE=FALSE # Enable timeline search, WARNING this greatly increases your chance of getting banned
TWITTER_TARGET_USERS= # Comma separated list of Twitter user names to interact with
X_SERVER_URL=
XAI_API_KEY=
XAI_MODEL=
Expand All @@ -62,6 +64,10 @@ POST_INTERVAL_MIN= # Default: 90
POST_INTERVAL_MAX= # Default: 180
POST_IMMEDIATELY=

# Twitter action processing configuration
ACTION_INTERVAL=300000 # Interval in milliseconds between action processing runs (default: 5 minutes)
ENABLE_ACTION_PROCESSING=false # Set to true to enable the action processing loop

# Feature Flags
IMAGE_GEN= # Set to TRUE to enable image generation
USE_OPENAI_EMBEDDING= # Set to TRUE for OpenAI/1536, leave blank for local
Expand Down
55 changes: 55 additions & 0 deletions .github/workflows/integrationTests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: integration-test
on:
push:
branches:
- "*"
pull_request:
branches:
- "*"
jobs:
smoke-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: pnpm/action-setup@v3
with:
version: 9.4.0

- uses: actions/setup-node@v4
with:
node-version: "23"
cache: "pnpm"

- name: Run smoke tests
run: pnpm run smokeTests
integration-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: pnpm/action-setup@v3
with:
version: 9.4.0

- uses: actions/setup-node@v4
with:
node-version: "23"
cache: "pnpm"

- name: Install dependencies
run: pnpm install -r

- name: Build packages
run: pnpm build

- name: Run integration tests
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
run: |
if [ -z "$OPENAI_API_KEY" ]; then
echo "Skipping integration tests due to missing required API keys"
exit 1
else
pnpm run integrationTests
fi
17 changes: 17 additions & 0 deletions agent/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ export async function initializeClients(
}

if (clientTypes.includes("twitter")) {
TwitterClientInterface.enableSearch = !isFalsish(getSecret(character, "TWITTER_SEARCH_ENABLE"));
const twitterClients = await TwitterClientInterface.start(runtime);
clients.push(twitterClients);
}
Expand All @@ -358,6 +359,22 @@ export async function initializeClients(
return clients;
}

function isFalsish(input: any): boolean {
// If the input is exactly NaN, return true
if (Number.isNaN(input)) {
return true;
}

// Convert input to a string if it's not null or undefined
const value = input == null ? '' : String(input);

// List of common falsish string representations
const falsishValues = ['false', '0', 'no', 'n', 'off', 'null', 'undefined', ''];

// Check if the value (trimmed and lowercased) is in the falsish list
return falsishValues.includes(value.trim().toLowerCase());
}

function getSecret(character: Character, secret: string) {
return character.settings.secrets?.[secret] || process.env[secret];
}
Expand Down
113 changes: 113 additions & 0 deletions docs/community/Streams/12-2024/2024-12-10.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
---
sidebar_position: 4
title: "AI Agent Dev School Part 4"
description: "AI Pizza: Hacking Eliza for Domino's Delivery (plus TEE Deep Dive)"
---

# AI Agent Dev School Part 4

**AI Pizza: Hacking Eliza for Domino's Delivery (plus TEE Deep Dive)**

Date: 2024-12-10
YouTube Link: https://www.youtube.com/watch?v=6I9e9pJprDI

## Timestamps

Part 1: Trusted Execution Environments (TEEs) with Agent Joshua
- **00:00:09** - Stream starts, initial setup issues.
- Link: <https://www.youtube.com/watch?v=6I9e9pJprDI&t=9>
- **00:01:58** - Intro to Trusted Execution Environments (TEEs).
- Link: <https://www.youtube.com/watch?v=6I9e9pJprDI&t=118>
- **00:08:03** - Agent Joshua begins explaining TEEs and the Eliza plugin.
- Link: <https://www.youtube.com/watch?v=6I9e9pJprDI&t=483>
- **00:19:15** - Deeper dive into remote attestation.
- Link: <https://www.youtube.com/watch?v=6I9e9pJprDI&t=1155>
- **00:24:50** - Discussion of derived keys.
- Link: <https://www.youtube.com/watch?v=6I9e9pJprDI&t=1490>
- **00:37:00** - Deploying to a real TEE, Phala Network's TEE cloud.
- Link: <https://www.youtube.com/watch?v=6I9e9pJprDI&t=2220>
- **00:50:48** - Q&A with Joshua, contact info, and next steps.
- Link: <https://www.youtube.com/watch?v=6I9e9pJprDI&t=3048>

Part 2: Building a Domino's pizza ordering agent
- **01:04:37** - Transition to building a Domino's pizza ordering agent.
- Link: <https://www.youtube.com/watch?v=6I9e9pJprDI&t=3877>
- **01:14:20** - Discussion of the pizza ordering agent’s order flow and state machine.
- Link: <https://www.youtube.com/watch?v=6I9e9pJprDI&t=4460>
- **01:22:07** - Using Claude to generate a state machine diagram.
- Link: <https://www.youtube.com/watch?v=6I9e9pJprDI&t=4927>
- **01:32:17** - Creating the Domino's plugin in Eliza.
- Link: <https://www.youtube.com/watch?v=6I9e9pJprDI&t=5537>
- **01:54:15** - Working on the pizza order provider.
- Link: <https://www.youtube.com/watch?v=6I9e9pJprDI&t=6855>
- **02:16:46** - Pizza provider code completed.
- Link: <https://www.youtube.com/watch?v=6I9e9pJprDI&t=8206>
- **02:28:50** - Discussion of caching customer and order data.
- Link: <https://www.youtube.com/watch?v=6I9e9pJprDI&t=8930>
- **03:13:45** - Pushing fixes to main branch and continuing work on the agent.
- Link: <https://www.youtube.com/watch?v=6I9e9pJprDI&t=11625>
- **04:24:30** - Discussion of summarizing past agent dev school sessions.
- Link: <https://www.youtube.com/watch?v=6I9e9pJprDI&t=15870>
- **05:01:18** - Shaw returns, admits to ordering Domino's manually.
- Link: <https://www.youtube.com/watch?v=6I9e9pJprDI&t=18078>
- **05:09:00** - Discussing payment flow and a confirm order action.
- Link: <https://www.youtube.com/watch?v=6I9e9pJprDI&t=18540>
- **05:27:17** - Final code push, wrap-up, and end of stream.
- Link: <https://www.youtube.com/watch?v=6I9e9pJprDI&t=19637>


## Summary

This is a livestream titled "AI Agent Dev School Part 4" from the ai16z project, featuring Shaw. The stream is divided into two main parts: a technical discussion on Trusted Execution Environments (TEEs) and a coding session where Shaw attempts to build a pizza-ordering agent using the Domino's API.

**Part 1: Trusted Execution Environments (TEEs) with Agent Joshua**

This segment begins with Shaw introducing the concept of TEEs and their importance for running autonomous agents securely. He emphasizes the need to protect private keys and ensure that code execution is tamper-proof. Joshua from the Phala Network is brought on to explain TEEs in more detail and demonstrate how to use the TEE plugin he built for Eliza.

* **Key Concepts:**
* **Trusted Execution Environments (TEEs):** Secure areas within a processor that isolate code and data, protecting them from unauthorized access and tampering.
* **Secure Enclave:** A cryptographic primitive that allows data to be encrypted and isolated within a processor.
* **Remote Attestation:** A method to verify that a program running inside a TEE is genuine and hasn't been tampered with, providing verifiability to users.
* **D-Stack:** An SDK developed in collaboration with Flashbots and Andrew Miller, enabling developers to build and launch Docker containers in TEEs.
* **Derived Key Provider:** A component that generates cryptographic keys based on a secret salt, ensuring that private keys are not exposed to humans.

* **Demonstration:**
* Joshua walks through the process of setting up and deploying an Eliza agent in a TEE simulator, demonstrating how to generate remote attestations and derive keys.
* He shows how to use the remote attestation explorer to verify the authenticity of the agent running inside the TEE.
* He explains how to build a Docker image of the agent and deploy it to the Phala Network's TEE cloud solution.

* **Use Cases:**
* Securely storing private keys for on-chain actions.
* Ensuring the integrity of autonomous agents, preventing tampering or unauthorized access.
* Providing verifiable execution for users and investors.

* **Phala Network's TEE Cloud:**
* Joshua introduces Phala Network's TEE cloud solution, which allows developers to deploy Docker images and host their agents in a trusted execution environment.
* He mentions that the service supports various compute-intensive applications beyond AI agents.
* He invites interested developers to contact him on Discord (@hashwarlock) for onboarding and further details.

**Part 2: Building a Pizza Ordering Agent**

In the second part, Shaw transitions to a more lighthearted coding session where he attempts to build an agent that can order a pizza using the Domino's API. He highlights the challenges of handling payments securely and connecting user information to the conversation.

* **Challenges:**
* Securely handling payment information.
* Connecting user data to the current conversation.
* Defining the order flow using a state machine.

* **Approach:**
* Shaw uses a state machine to model the pizza ordering process, defining different states and transitions based on user input and available information.
* He uses Claude (an AI assistant) to generate code snippets and assist with the development process.
* He decides to initially focus on a simplified version where the user's payment information is hardcoded in the environment variables, and the agent only needs to collect the user's address.

## Hot Takes

1. **"Maybe we'll mix it on LinkedIn so people can order Domino's on LinkedIn. There you go. Now we're cooking." (00:03:26)** - Shaw's seemingly flippant idea of ordering pizza on LinkedIn highlights the potential for integrating everyday services into unexpected platforms through agents. This sparked discussion about the wider implications for businesses and social media.

2. **"Yeah, it'll probably get drained real quick. These fucking people." (00:28:30)** - Shaw accidentally leaked an API key on stream and expressed frustration with viewers who noticed, exposing the real-world risks of handling sensitive information during development, especially in a live environment.

3. **"The secret to making a billion dollars is to use the existing agent framework to deliver apps to people on social media that they want." (01:09:35)** - Shaw’s strong assertion about focusing on building apps *using* existing frameworks rather than creating new ones is a bold statement about the current agent development landscape, suggesting that innovation lies in application development, not framework creation.

4. **"So those are like, honest to God, if the bots are better than like 70% of tweets on Twitter, they're better than like 99.7 tweets and posts on LinkedIn." (01:39:57)** - This provocative comparison of content quality between Twitter and LinkedIn, suggesting bots surpass most LinkedIn posts, fueled lively debate in the chat and raised questions about the role and value of human-generated content in the age of AI.

5. **"I subliminally messaged Domino's into my own brain, and now I have to eat it." (05:01:24)** - After hours of working on the pizza bot, Shaw abandoned the live coding attempt and ordered pizza manually, a humorous but relatable moment that highlighted the challenges and frustrations of software development, even when aided by AI. It also underscores the human desire for immediate gratification, even in the face of a potentially groundbreaking technological advancement.
47 changes: 47 additions & 0 deletions docs/docs/core/characterfile.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,53 @@ The `settings` object defines additional configurations like secrets and voice m
}
```

### Templates Configuration

The `templates` object defines customizable prompt templates used for various tasks and interactions. Below is the list of available templates:

- `goalsTemplate`
- `factsTemplate`
- `messageHandlerTemplate`
- `shouldRespondTemplate`
- `continueMessageHandlerTemplate`
- `evaluationTemplate`
- `twitterSearchTemplate`
- `twitterPostTemplate`
- `twitterMessageHandlerTemplate`
- `twitterShouldRespondTemplate`
- `telegramMessageHandlerTemplate`
- `telegramShouldRespondTemplate`
- `discordVoiceHandlerTemplate`
- `discordShouldRespondTemplate`
- `discordMessageHandlerTemplate`

### Example: Twitter Post Template

Here’s an example of a `twitterPostTemplate`:

```js
templates: {
twitterPostTemplate: `
# Areas of Expertise
{{knowledge}}
# About {{agentName}} (@{{twitterUserName}}):
{{bio}}
{{lore}}
{{topics}}
{{providers}}
{{characterPostExamples}}
{{postDirections}}
# Task: Generate a post in the voice and style and perspective of {{agentName}} @{{twitterUserName}}.
Write a 1-3 sentence post that is {{adjective}} about {{topic}} (without mentioning {{topic}} directly), from the perspective of {{agentName}}. Do not add commentary or acknowledge this request, just write the post.
Your response should not contain any questions. Brief, concise statements only. The total character count MUST be less than {{maxTweetLength}}. No emojis. Use \\n\\n (double spaces) between statements.`,
}
```

---

## Example: Complete Character File
Expand Down
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
"docker:bash": "bash ./scripts/docker.sh bash",
"docker:start": "bash ./scripts/docker.sh start",
"docker": "pnpm docker:build && pnpm docker:run && pnpm docker:bash",
"test": "bash ./scripts/test.sh"
"test": "bash ./scripts/test.sh",
"smokeTests": "bash ./scripts/smokeTests.sh",
"integrationTests": "bash ./scripts/integrationTests.sh"
},
"devDependencies": {
"@commitlint/cli": "18.6.1",
Expand All @@ -38,7 +40,8 @@
"typedoc": "0.26.11",
"typescript": "5.6.3",
"vite": "5.4.11",
"vitest": "2.1.5"
"vitest": "2.1.5",
"zx": "^8.2.4"
},
"pnpm": {
"overrides": {
Expand Down
40 changes: 40 additions & 0 deletions packages/client-twitter/src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,46 @@ export class ClientBase extends EventEmitter {
// });
}

async fetchFeedTimeline(count: number): Promise<string> {
elizaLogger.debug("fetching home timeline");
const homeTimeline = await this.twitterClient.fetchHomeTimeline(count, []);
return homeTimeline
.filter(tweet => tweet.text || tweet.legacy?.full_text)
.sort((a, b) => {
const timestampA = new Date(a.createdAt ?? a.legacy?.created_at).getTime();
const timestampB = new Date(b.createdAt ?? b.legacy?.created_at).getTime();
return timestampB - timestampA;
})
.slice(0, count)
.map(tweet =>
`@${tweet.username || tweet.core?.user_results?.result?.legacy?.screen_name}: ${tweet.text ?? tweet.legacy?.full_text ?? ''}`
)
.join('\n');
}

async fetchTimelineForActions(count: number): Promise<Tweet[]> {
elizaLogger.debug("fetching timeline for actions");
const homeTimeline = await this.twitterClient.fetchHomeTimeline(count, []);

return homeTimeline.map(tweet => ({
id: tweet.rest_id,
name: tweet.core?.user_results?.result?.legacy?.name,
username: tweet.core?.user_results?.result?.legacy?.screen_name,
text: tweet.legacy?.full_text,
inReplyToStatusId: tweet.legacy?.in_reply_to_status_id_str,
timestamp: new Date(tweet.legacy?.created_at).getTime() / 1000,
userId: tweet.legacy?.user_id_str,
conversationId: tweet.legacy?.conversation_id_str,
permanentUrl: `https://twitter.com/${tweet.core?.user_results?.result?.legacy?.screen_name}/status/${tweet.rest_id}`,
hashtags: tweet.legacy?.entities?.hashtags || [],
mentions: tweet.legacy?.entities?.user_mentions || [],
photos: tweet.legacy?.entities?.media?.filter(media => media.type === "photo") || [],
thread: tweet.thread || [],
urls: tweet.legacy?.entities?.urls || [],
videos: tweet.legacy?.entities?.media?.filter(media => media.type === "video") || []
}));
}

async fetchSearchTweets(
query: string,
maxTweets: number,
Expand Down
22 changes: 16 additions & 6 deletions packages/client-twitter/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,34 @@ class TwitterManager {
post: TwitterPostClient;
search: TwitterSearchClient;
interaction: TwitterInteractionClient;
constructor(runtime: IAgentRuntime) {
constructor(runtime: IAgentRuntime, enableSearch:boolean) {
this.client = new ClientBase(runtime);
this.post = new TwitterPostClient(this.client, runtime);
//this.search = new TwitterSearchClient(this.client, runtime); // don't start the search client by default
// this searches topics from character file, but kind of violates consent of random users
// burns your rate limit and can get your account banned
// use at your own risk

if (enableSearch) {
// this searches topics from character file
elizaLogger.warn('Twitter/X client running in a mode that:')
elizaLogger.warn('1. violates consent of random users')
elizaLogger.warn('2. burns your rate limit')
elizaLogger.warn('3. can get your account banned')
elizaLogger.warn('use at your own risk')
this.search = new TwitterSearchClient(this.client, runtime); // don't start the search client by default
}
this.interaction = new TwitterInteractionClient(this.client, runtime);
}
}

export const TwitterClientInterface: Client = {

async start(runtime: IAgentRuntime) {
await validateTwitterConfig(runtime);

elizaLogger.log("Twitter client started");

const manager = new TwitterManager(runtime);
// enableSearch is just set previous to this call
// so enableSearch can change over time
// and changing it won't stop the SearchClient in the existing instance
const manager = new TwitterManager(runtime, this.enableSearch);

await manager.client.init();

Expand Down
Loading

0 comments on commit bedb291

Please sign in to comment.