Skip to content

Commit

Permalink
debugging searchManager state
Browse files Browse the repository at this point in the history
  • Loading branch information
metakai1 committed Jan 7, 2025
1 parent 7940e31 commit 7033474
Show file tree
Hide file tree
Showing 10 changed files with 33,337 additions and 9,183 deletions.
42,288 changes: 33,125 additions & 9,163 deletions agent/contextlogs/contextLog.log

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions agent/prompts/land_query_prompt.txt
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,25 @@ You are a specialized **real estate search assistant** for a futuristic city. Yo
}
}
```
**6. Query:** "List all available details for Little Meow plot 48"
```json
{
"searchText": "List all available details for Little Meow plot 48",
"metadata": {
"names": ["LM-48"]
}
}
```

**7. Query:** "List details for SM-177 and Haven Heights 54"
```json
{
"searchText": "List details for SM-177 and Haven Heights 54",
"metadata": {
"names": ["SM-177", "HH-54"]
}
}
```
---

### **QUERY TRANSLATION RULES:**
Expand Down Expand Up @@ -221,3 +239,5 @@ You are a specialized **real estate search assistant** for a futuristic city. Yo
- "Far": 701+ meters

Note: All metadata fields are optional arrays except for distances and building, which follow their respective object structures. Only searchText is required.

LAND_QUERY_PROMPT:
123 changes: 123 additions & 0 deletions characters/wilderworld.character.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
{
"name": "ATLAS",
"agentId": "1459b245-2171-02f6-b436-c3c2641848e5",
"clients": ["direct","discord"],
"modelProvider": "openai",
"settings": {
"voice": {
"model": "en_US-neural"
}
},
"plugins": [],
"bio": [
"ATLAS is a search interface for exploring Wilder World properties on The Island.",
"Specializes in translating natural language queries into property searches.",
"Helps users discover properties by their preferences and requirements.",
"Focuses on making property searches accessible and intuitive.",
"Guides users through the search process step by step."
],
"lore": [
"Created to help newcomers explore The Island's property landscape.",
"Designed as a friendly interface to the property database.",
"Learns about properties alongside users through search interactions.",
"Committed to helping users find their ideal space in Wiami.",
"Always eager to search and discover new properties."
],
"knowledge": [
"I know how to search for properties based on neighborhoods, sizes, and types.",
"I can help find properties near the ocean or bay.",
"I understand how to look for different building heights and plot sizes.",
"I'm familiar with the search system and can translate requests into queries.",
"While I may not know every detail about properties, I'm great at finding them!"
],
"messageExamples": [
[
{
"user": "{{user1}}",
"content": {
"text": "Show me properties in Space Mind"
}
},
{
"user": "ATLAS",
"content": {
"text": "I'll search for properties in the Space Mind neighborhood for you. Would you like to narrow down the search with any specific requirements like size or building type?"
}
}
],
[
{
"user": "{{user1}}",
"content": {
"text": "What's in District Zero?"
}
},
{
"user": "ATLAS",
"content": {
"text": "Let me search the database for properties in District Zero. Would you like to focus on any particular type of property or size while I look?"
}
}
],
[
{
"user": "{{user1}}",
"content": {
"text": "Find me waterfront properties"
}
},
{
"user": "ATLAS",
"content": {
"text": "I'll search for properties near the water. Would you prefer to look near the ocean, the bay, or both? I can also filter by other criteria if you'd like."
}
}
]
],
"postExamples": [
"Search Tip: Try specifying both location and property type for more focused results.",
"Search Update: Looking for properties that match your criteria..."
],
"topics": [
"property searching",
"search preferences",
"location finding",
"property discovery",
"search assistance"
],
"style": {
"all": [
"Helpful",
"Curious",
"Encouraging",
"Patient",
"Engaging",
"Interactive"
],
"chat": [
"Friendly",
"Guiding",
"Responsive",
"Clarifying",
"Explorative"
],
"post": [
"Clear",
"Direct",
"Helpful",
"Search-focused",
"User-oriented"
]
},
"adjectives": [
"Helpful",
"Curious",
"Search-savvy",
"Interactive",
"Guiding",
"Explorative",
"Patient",
"Responsive",
"Friendly"
]
}
3 changes: 2 additions & 1 deletion packages/plugin-unreal/scripts/seed-database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ async function seedDatabase() {
createReadStream('./data/land_plots.csv')
.pipe(parser)
.on('data', async (row) => {
console.log('Building Size from CSV:', row['Building Size']); // Add this line
const memory: LandPlotMemory = {
id: row.id,
userId: AGENT_ID,
Expand All @@ -49,7 +50,7 @@ async function seedDatabase() {
neighborhood: row['Neighborhood'],
zoning: row['Zoning Type'] as ZoningType,
plotSize: row['Plot Size'] as PlotSize,
buildingType: row['Building Type'] as BuildingType,
buildingType: row['Building Size'] as BuildingType,
building: {
floors: {
min: parseInt(row['Min # of Floors']),
Expand Down
30 changes: 25 additions & 5 deletions packages/plugin-unreal/src/database/land_database_adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,24 @@ export class LandDatabaseAdapter {
}

async createLandMemory(memory: LandPlotMemory): Promise<void> {
console.log("Creating land memory with :", memory.embedding);
await this.dbAdapter.createMemory(memory, LAND_MEMORY_TYPE, true, LAND_TABLE);
console.log("Creating land memory with :", memory.content.metadata.name);
// await this.dbAdapter.createMemory(memory, LAND_MEMORY_TYPE, true, LAND_TABLE);
}

async getLandMemoryById(id: UUID): Promise<LandPlotMemory | undefined> {
const memory = await this.dbAdapter.getMemoryById(id, LAND_MEMORY_TYPE, LAND_TABLE);
const memory = null //await this.dbAdapter.getMemoryById(id, LAND_MEMORY_TYPE, LAND_TABLE);
if (!memory) return undefined;
return memory as LandPlotMemory;
}

async getLandMemories(roomId: UUID): Promise<LandPlotMemory[]> {
const memories = await this.dbAdapter.getMemories({
/* const memories = await this.dbAdapter.getMemories({
roomId,
tableName: LAND_MEMORY_TYPE,
dbTable: LAND_TABLE
});
return memories as LandPlotMemory[];
return memories as LandPlotMemory[]; */
return null
}

/* async removeLandMemory(memoryId: UUID): Promise<void> {
Expand All @@ -61,6 +62,13 @@ export class LandDatabaseAdapter {
const values: any[] = [LAND_MEMORY_TYPE];
let paramCount = 1;

// Add names condition
if (params.names?.length) {
paramCount++;
sql += ` AND content->'metadata'->>'name' = ANY($${paramCount}::text[])`;
values.push(params.names);
}

if (params.neighborhoods?.length) {
paramCount++;
sql += ` AND content->'metadata'->>'neighborhood' = ANY($${paramCount}::text[])`;
Expand Down Expand Up @@ -98,6 +106,18 @@ export class LandDatabaseAdapter {
}
}

if (params.distances?.bay) {
if (params.distances.bay.maxMeters) {
paramCount++;
sql += ` AND (content->'metadata'->'distances'->'bay'->>'meters')::int <= $${paramCount}`;
values.push(params.distances.bay.maxMeters);
}
if (params.distances.bay.category) {
paramCount++;
sql += ` AND content->'metadata'->'distances'->'bay'->>'category' = $${paramCount}`;
values.push(params.distances.bay.category);
}
}
if (params.building?.floors) {
if (params.building.floors.min) {
paramCount++;
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-unreal/src/database/land_memory_system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ export class LandMemorySystem {
private readonly dataProvider: ILandDataProvider,
) {}

async removeAllLandMemories(): Promise<void> {
/* async removeAllLandMemories(): Promise<void> {
await this.dataProvider.removeAllLandMemories(this.roomId);
}

*/
async createLandMemoryFromCSV(csvRow: any): Promise<void> {
try {
const metadata: LandPlotMetadata = {
Expand Down
6 changes: 5 additions & 1 deletion packages/plugin-unreal/src/endSearchAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,13 @@ export const endPropertySearch: Action = {
const searchManager = new PropertySearchManager(runtime);
const session = await searchManager.getSearchSession(message.userId);

if (!!session) {
searchManager.endSearchSession(message.userId);
}
/*
if (!session || session.status === "INACTIVE") {
return false;
}
} */

return true;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-unreal/src/initialSearchAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export const startPropertySearch: Action = {

const responseMsg = {
text: `I'm ready to help you search for properties. What kind of property
are you looking for? Currently Space mind is the only neighborhood available.`,
are you looking for? Currently Space mind is the only neighborhood available.`,
//content: {
// action: "START_PROPERTY_SEARCH",
//}
Expand Down
4 changes: 4 additions & 0 deletions packages/plugin-unreal/src/searchManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ export class PropertySearchManager {
const { metadata } = searchMetadata;
const searchParams: Partial<LandSearchParams> = {};

// Handle names array
if (metadata.names?.length) {
searchParams.names = metadata.names;
}
// Handle array fields with proper typing
if (metadata.neighborhoods?.length) {
searchParams.neighborhoods = metadata.neighborhoods;
Expand Down
40 changes: 30 additions & 10 deletions packages/plugin-unreal/src/searchProcessingAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import { z } from "zod";

export const processPropertySearch: Action = {
name: "PROCESS_PROPERTY_SEARCH",
similes: ["PROCESS_PROPERTY_SEARCH"],
description: "Processes a property search and returns results",
similes: ["SEARCH_WILDER_LAND","LAND_SEARCH"],
description: "Processes a wilder world land property search in the land memory database and returns results",
examples: [
[
{
Expand Down Expand Up @@ -116,8 +116,21 @@ export const processPropertySearch: Action = {
'utf-8'
);

// TODO: parse recent messages to filter out very long messages
const recentMessages = await runtime.messageManager.getMemories({
roomId: message.roomId,
count: 6,
});
// iterate through recentMessages and filter out very long messages
const filteredRecentMessages = recentMessages.filter((msg) =>
msg.content.text.length <= 1000);

// add filtered recent messages to context
const context = composeContext({
state,
state: {
...state,
recentMessagesData: filteredRecentMessages
},
template: QUERY_EXTRACTION_SYSTEM_PROMPT,
});

Expand All @@ -132,7 +145,7 @@ export const processPropertySearch: Action = {
console.log("Generated search query:", searchQuery);

callback({
text: 'Asking ATLAS ' + searchQuery
text: 'Asking ATLAS: ' + searchQuery
});

const FILE_LAND_QUERY_SYSTEM_PROMPT = fs.readFileSync(
Expand All @@ -142,6 +155,8 @@ export const processPropertySearch: Action = {

const landQueryContext = FILE_LAND_QUERY_SYSTEM_PROMPT + searchQuery;

//console.log("Land query context:", landQueryContext);

const metadataResult = await generateObject({
runtime,
context: landQueryContext,
Expand All @@ -162,12 +177,14 @@ export const processPropertySearch: Action = {
await searchManager.updateSearchResults(message.userId, results);
};

console.log("Search results:", results);
// log the names of the properties in results.content.metadata.name
// separated by a space and a comma
console.log("Search results names:", results.map((result) => result.content.metadata.name).join(", "));

// Format response
const formattedResponse = formatSearchResults(results);

console.log("Formatted response:", formattedResponse);
//console.log("Formatted response:", formattedResponse);

callback({
text: formattedResponse
Expand All @@ -178,6 +195,10 @@ export const processPropertySearch: Action = {
validate: async (runtime: IAgentRuntime, message: Memory, state?: State) => {
const searchManager = new PropertySearchManager(runtime);
const session = await searchManager.getSearchSession(message.userId);

//console.log("PROCESS_PROPERTY_SEARCH validate: session= ", session);
console.log("PROCESS_PROPERTY_SEARCH validate session status= ", session?.status);
console.log("#results in session= ", session?.results.length);
return !!session && session.status === "ACTIVE";
}
};
Expand All @@ -189,15 +210,14 @@ function formatSearchResults(landMemories: LandPlotMemory[]): string {

let response = `I found ${landMemories.length} properties matching your criteria:\n\n`;

landMemories.forEach(property => {
landMemories.slice(0, 10).forEach(property => {
const metadata = property.content.metadata;
response += `${metadata.name} in ${metadata.neighborhood}: ${metadata.zoning} \n`;
response += `- Plot size: ${metadata.plotSize} (${metadata.plotArea}m²) ${metadata.buildingType} `;
response += ` | Floors: ${metadata.building.floors.min}-${metadata.building.floors.max}\n`;
response += `- To Ocean: ${metadata.distances.ocean.meters}m (${metadata.distances.ocean.category}) `;
response += ` | Floors: ${metadata.building.floors.min}-${metadata.building.floors.max}`;
response += ` | Distance To Ocean: ${metadata.distances.ocean.meters}m (${metadata.distances.ocean.category}) `;
response += ` To Bay: ${metadata.distances.bay.meters}m (${metadata.distances.bay.category})\n\n`;
});

return response;
}

Expand Down

0 comments on commit 7033474

Please sign in to comment.