Skip to content

Commit 5b55784

Browse files
committed
get pull requests and add to memories
1 parent 81a963d commit 5b55784

File tree

6 files changed

+216
-180
lines changed

6 files changed

+216
-180
lines changed

packages/client-github/src/index.ts

+72-66
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
} from "@elizaos/plugin-github";
1616
import { isOODAContent, OODAContent, OODASchema } from "./types";
1717
import { oodaTemplate } from "./templates";
18-
import { saveIssuesToMemory } from "./utils";
18+
import { saveIssuesToMemory, savePullRequestsToMemory } from "./utils";
1919

2020
export class GitHubClient extends EventEmitter {
2121
apiToken: string;
@@ -87,71 +87,7 @@ export class GitHubClient extends EventEmitter {
8787
);
8888
// elizaLogger.log("Retrieved memories:", memories);
8989
if (fileMemories.length === 0) {
90-
elizaLogger.log("No memories found, skipping OODA cycle.");
91-
// time to initialize repository and create memories
92-
const timestamp = Date.now();
93-
const userIdUUID = stringToUuid(`${this.runtime.agentId}-${timestamp}`);
94-
const originalMemory: Memory = {
95-
id: stringToUuid(`${roomId}-${this.runtime.agentId}-${timestamp}-original`),
96-
userId: userIdUUID,
97-
agentId: this.runtime.agentId,
98-
content: {
99-
text: `No memories found, starting to initialize repository and create memories.`,
100-
action: "NOTHING",
101-
source: "github",
102-
inReplyTo: stringToUuid(`${roomId}-${this.runtime.agentId}`)
103-
},
104-
roomId,
105-
createdAt: timestamp,
106-
}
107-
let originalState = await this.runtime.composeState(originalMemory);
108-
originalState = await incorporateRepositoryState(originalState, this.runtime, originalMemory, []);
109-
const initializeRepositoryMemory: Memory = {
110-
id: stringToUuid(`${roomId}-${this.runtime.agentId}-${timestamp}-initialize-repository`),
111-
userId: userIdUUID,
112-
agentId: this.runtime.agentId,
113-
content: {
114-
text: `Initialize the repository ${owner}/${repository} on sif-dev branch`,
115-
action: "INITIALIZE_REPOSITORY",
116-
source: "github",
117-
inReplyTo: stringToUuid(`${roomId}-${this.runtime.agentId}`)
118-
},
119-
roomId,
120-
createdAt: timestamp,
121-
}
122-
await this.runtime.messageManager.createMemory(initializeRepositoryMemory);
123-
elizaLogger.debug("Memory created successfully:", {
124-
memoryId: initializeRepositoryMemory.id,
125-
action: initializeRepositoryMemory.content.action,
126-
userId: this.runtime.agentId,
127-
});
128-
const createMemoriesFromFilesMemory = {
129-
id: stringToUuid(`${roomId}-${this.runtime.agentId}-${timestamp}-create-memories-from-files`),
130-
userId: userIdUUID,
131-
agentId: this.runtime.agentId,
132-
content: {
133-
text: `Create memories from files for the repository ${owner}/${repository} at path '/'`,
134-
action: "CREATE_MEMORIES_FROM_FILES",
135-
source: "github",
136-
inReplyTo: stringToUuid(`${roomId}-${this.runtime.agentId}`)
137-
},
138-
roomId,
139-
createdAt: timestamp,
140-
}
141-
await this.runtime.messageManager.createMemory(createMemoriesFromFilesMemory);
142-
elizaLogger.debug("Memory created successfully:", {
143-
memoryId: createMemoriesFromFilesMemory.id,
144-
action: createMemoriesFromFilesMemory.content.action,
145-
userId: this.runtime.agentId,
146-
});
147-
const issuesMemories = await saveIssuesToMemory(this.runtime, owner, repository, this.apiToken);
148-
elizaLogger.log("Issues memories:", issuesMemories);
149-
await this.runtime.processActions(
150-
originalMemory,
151-
[initializeRepositoryMemory, createMemoriesFromFilesMemory],
152-
originalState,
153-
undefined
154-
);
90+
await this.initializeRepositoryAndCreateMemories(owner, repository, roomId);
15591
}
15692

15793
elizaLogger.log('Before composeState')
@@ -251,6 +187,76 @@ export class GitHubClient extends EventEmitter {
251187
elizaLogger.log("OODA cycle completed.");
252188
}
253189

190+
private async initializeRepositoryAndCreateMemories(owner: string, repository: string, roomId: UUID) {
191+
elizaLogger.log("No memories found, skipping OODA cycle.");
192+
// time to initialize repository and create memories
193+
const timestamp = Date.now();
194+
const userIdUUID = stringToUuid(`${this.runtime.agentId}-${timestamp}`);
195+
const originalMemory: Memory = {
196+
id: stringToUuid(`${roomId}-${this.runtime.agentId}-${timestamp}-original`),
197+
userId: userIdUUID,
198+
agentId: this.runtime.agentId,
199+
content: {
200+
text: `No memories found, starting to initialize repository and create memories.`,
201+
action: "NOTHING",
202+
source: "github",
203+
inReplyTo: stringToUuid(`${roomId}-${this.runtime.agentId}`)
204+
},
205+
roomId,
206+
createdAt: timestamp,
207+
}
208+
let originalState = await this.runtime.composeState(originalMemory);
209+
originalState = await incorporateRepositoryState(originalState, this.runtime, originalMemory, []);
210+
const initializeRepositoryMemory: Memory = {
211+
id: stringToUuid(`${roomId}-${this.runtime.agentId}-${timestamp}-initialize-repository`),
212+
userId: userIdUUID,
213+
agentId: this.runtime.agentId,
214+
content: {
215+
text: `Initialize the repository ${owner}/${repository} on sif-dev branch`,
216+
action: "INITIALIZE_REPOSITORY",
217+
source: "github",
218+
inReplyTo: stringToUuid(`${roomId}-${this.runtime.agentId}`)
219+
},
220+
roomId,
221+
createdAt: timestamp,
222+
}
223+
await this.runtime.messageManager.createMemory(initializeRepositoryMemory);
224+
elizaLogger.debug("Memory created successfully:", {
225+
memoryId: initializeRepositoryMemory.id,
226+
action: initializeRepositoryMemory.content.action,
227+
userId: this.runtime.agentId,
228+
});
229+
const createMemoriesFromFilesMemory = {
230+
id: stringToUuid(`${roomId}-${this.runtime.agentId}-${timestamp}-create-memories-from-files`),
231+
userId: userIdUUID,
232+
agentId: this.runtime.agentId,
233+
content: {
234+
text: `Create memories from files for the repository ${owner}/${repository} at path '/'`,
235+
action: "CREATE_MEMORIES_FROM_FILES",
236+
source: "github",
237+
inReplyTo: stringToUuid(`${roomId}-${this.runtime.agentId}`)
238+
},
239+
roomId,
240+
createdAt: timestamp,
241+
}
242+
await this.runtime.messageManager.createMemory(createMemoriesFromFilesMemory);
243+
elizaLogger.debug("Memory created successfully:", {
244+
memoryId: createMemoriesFromFilesMemory.id,
245+
action: createMemoriesFromFilesMemory.content.action,
246+
userId: this.runtime.agentId,
247+
});
248+
const issuesMemories = await saveIssuesToMemory(this.runtime, owner, repository, this.apiToken);
249+
elizaLogger.log("Issues memories:", issuesMemories);
250+
const pullRequestsMemories = await savePullRequestsToMemory(this.runtime, owner, repository, this.apiToken);
251+
elizaLogger.log("Pull requests memories:", pullRequestsMemories);
252+
253+
await this.runtime.processActions(
254+
originalMemory,
255+
[initializeRepositoryMemory, createMemoriesFromFilesMemory],
256+
originalState,
257+
undefined
258+
);
259+
}
254260
}
255261

256262
export const GitHubClientInterface: Client = {
+22-105
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,9 @@
1+
import { contextTemplate } from "@elizaos/plugin-github";
2+
13
export const oodaTemplate = `
24
# INSTRUCTIONS:
35
You are an AI agent tasked with analyzing repository files and making strategic improvements. Your response should be systematic and data-driven.
46
5-
## Your Character:
6-
{{character}}
7-
8-
## Historical Context:
9-
Review and consider these previous interactions:
10-
- Previous Pull Requests: {{previousPRs}}
11-
- Previous Issues: {{previousIssues}}
12-
13-
## Repository Context:
14-
Current workspace:
15-
- Repository: {{repository}}
16-
- Owner: {{owner}}
17-
- Files for analysis: {{files}}
18-
197
## Task Instructions:
208
1. Analyze the provided files systematically
219
2. Consider the repository's history and current state
@@ -24,11 +12,14 @@ export const oodaTemplate = `
2412
5. Select the most impactful action based on your analysis
2513
6. Format your response according to the schema below
2614
15+
${contextTemplate}
2716
## Response Schema:
2817
Choose ONE action from the following options and provide ALL required fields:
2918
3019
Action Options:
3120
1. CREATE_ISSUE: For identifying problems or suggesting improvements
21+
2. ADD_COMMENT_TO_ISSUE: For following up on an issue if you have more information
22+
3. ADD_COMMENT_TO_PR: For providing feedback on a pull request
3223
2. NOTHING: When no action is needed
3324
3425
Required Fields:
@@ -49,61 +40,17 @@ export const oodaTemplate = `
4940
- labels: (optional) Relevant labels
5041
- issue: (required for issue operations) Issue number
5142
52-
## Response Examples:
53-
54-
1. INITIALIZE_REPOSITORY:
55-
{
56-
"action": "INITIALIZE_REPOSITORY",
57-
"reasoning": "Repository needs initialization to establish basic structure and main branch",
58-
"owner": "octocat",
59-
"repo": "hello-world",
60-
"branch": "main"
61-
}
62-
63-
2. CREATE_MEMORIES_FROM_FILES:
64-
{
65-
"action": "CREATE_MEMORIES_FROM_FILES",
66-
"reasoning": "Need to process and store repository content for future analysis",
67-
"owner": "octocat",
68-
"repo": "hello-world",
69-
"path": "src/memories"
70-
}
71-
72-
3. CREATE_PULL_REQUEST:
73-
{
74-
"action": "CREATE_PULL_REQUEST",
75-
"reasoning": "Implementation of new feature requires code review and team discussion",
76-
"owner": "octocat",
77-
"repo": "hello-world",
78-
"base": "main",
79-
"branch": "feature/new-feature",
80-
"title": "Add new feature",
81-
"description": "This PR implements the new feature with the following improvements:\\n\\n1. Feature benefit A\\n2. Feature benefit B\\n\\nTesting completed:\\n- Unit tests added\\n- Integration tests passed",
82-
"files": [
83-
{
84-
"path": "src/newFeature.ts",
85-
"content": "// New feature implementation"
86-
}
87-
]
88-
}
43+
Remember to:
44+
1. Provide complete and valid JSON
45+
2. Include all required fields for your chosen action
46+
3. Use clear, descriptive messages
47+
4. Follow repository conventions
48+
5. Consider the impact of your action
49+
6. Ensure no duplicate issues or pull requests are created
8950
90-
4. CREATE_COMMIT:
91-
{
92-
"action": "CREATE_COMMIT",
93-
"reasoning": "Commit is needed to update documentation with new configuration options",
94-
"owner": "octocat",
95-
"repo": "hello-world",
96-
"branch": "main",
97-
"message": "docs: update README with new configuration options",
98-
"files": [
99-
{
100-
"path": "docs/README.md",
101-
"content": "Updated content"
102-
}
103-
]
104-
}
51+
## Response Examples:
10552
106-
5. CREATE_ISSUE:
53+
1. CREATE_ISSUE:
10754
{
10855
"action": "CREATE_ISSUE",
10956
"reasoning": "Issue is needed to identify performance issue and propose solution",
@@ -114,20 +61,7 @@ export const oodaTemplate = `
11461
"labels": ["performance", "high-priority"]
11562
}
11663
117-
6. MODIFY_ISSUE:
118-
{
119-
"action": "MODIFY_ISSUE",
120-
"reasoning": "Issue is updated to reflect new information or progress",
121-
"owner": "octocat",
122-
"repo": "hello-world",
123-
"issue": 123,
124-
"title": "Updated: Optimize database queries",
125-
"body": "## Update\\n[New information or progress]\\n\\n## Original Issue\\n[Original content]",
126-
"state": "closed",
127-
"labels": ["resolved"]
128-
}
129-
130-
7. ADD_COMMENT_TO_ISSUE:
64+
2. ADD_COMMENT_TO_ISSUE:
13165
{
13266
"action": "ADD_COMMENT_TO_ISSUE",
13367
"reasoning": "Comment is added to provide progress update",
@@ -137,36 +71,19 @@ export const oodaTemplate = `
13771
"comment": "## Progress Update\\n- Completed X\\n- Found Y\\n- Next steps: Z"
13872
}
13973
140-
8. NOTHING:
141-
{
142-
"action": "NOTHING"
143-
}
144-
145-
9. COMMENT_ISSUE:
146-
{
147-
"action": "COMMENT_ISSUE",
148-
"reasoning": "Comment is added to provide analysis findings and recommended next steps",
149-
"owner": "octocat",
150-
"repo": "hello-world",
151-
"issue": 123,
152-
"comment": "I've analyzed this issue and here are my findings:\\n\\n1. [Analysis point 1]\\n2. [Analysis point 2]\\n\\nRecommended next steps:\\n- Step 1\\n- Step 2"
153-
}
154-
155-
10. COMMENT_PR:
74+
3. ADD_COMMENT_TO_PR:
15675
{
157-
"action": "COMMENT_PR",
76+
"action": "ADD_COMMENT_TO_PR",
15877
"reasoning": "Pull request needs feedback on implementation approach and code quality",
15978
"owner": "octocat",
16079
"repo": "hello-world",
16180
"issue": 456,
16281
"comment": "## Code Review Feedback\\n\\n### Strengths\\n- [Positive point 1]\\n- [Positive point 2]\\n\\n### Suggestions\\n- [Suggestion 1]\\n- [Suggestion 2]\\n\\nOverall: [Summary]"
16382
}
16483
165-
Remember to:
166-
1. Provide complete and valid JSON
167-
2. Include all required fields for your chosen action
168-
3. Use clear, descriptive messages
169-
4. Follow repository conventions
170-
5. Consider the impact of your action
171-
6. Ensure no duplicate issues or pull requests are created
84+
4. NOTHING:
85+
{
86+
"action": "NOTHING",
87+
"reasoning": "No action is needed because the current state meets all requirements and no further changes are necessary."
88+
}
17289
`

0 commit comments

Comments
 (0)