Skip to content

Commit

Permalink
fix memory response type
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh-XT committed Jan 7, 2025
1 parent d74a420 commit db14134
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 39 deletions.
76 changes: 53 additions & 23 deletions agixt/graphqlendpoints/Extensions.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
from typing import List, Dict, Any, Optional
import strawberry
from fastapi import Depends, HTTPException, Header
from Models import (
CommandExecution,
CommandArgs,
ExtensionsModel,
ExtensionSettings,
)
from Extensions import Extensions
from ApiClient import Agent, Conversations, verify_api_key, get_api_client, is_admin
from fastapi import HTTPException
from Models import CommandExecution
from ApiClient import verify_api_key, is_admin
from endpoints.Extension import (
get_extension_settings as rest_get_extension_settings,
get_command_args as rest_get_command_args,
Expand All @@ -18,20 +12,56 @@
)


# Convert Pydantic models to Strawberry types
@strawberry.experimental.pydantic.type(model=ExtensionSettings)
class ExtensionSettingsType:
extension_settings: Dict[str, Dict[str, Any]]


@strawberry.experimental.pydantic.type(model=CommandArgs)
class CommandArgsType:
command_args: Dict[str, Any]


@strawberry.experimental.pydantic.type(model=ExtensionsModel)
class ExtensionsModelType:
extensions: List[Dict[str, Any]]
""" get_agent_extensions output:
{"extensions": [{"extension_settings": {'sendgrid_email': {'SENDGRID_API_KEY': '', 'SENDGRID_EMAIL': ''},
'postgres_database': {'POSTGRES_DATABASE_NAME': '',
'POSTGRES_DATABASE_HOST': '',
'POSTGRES_DATABASE_PORT': 5432,
'POSTGRES_DATABASE_USERNAME': '',
'POSTGRES_DATABASE_PASSWORD': ''},
'google_search': {'GOOGLE_API_KEY': '', 'GOOGLE_SEARCH_ENGINE_ID': ''},
'mysql_database': {'MYSQL_DATABASE_NAME': '',
'MYSQL_DATABASE_HOST': '',
'MYSQL_DATABASE_PORT': 3306,
'MYSQL_DATABASE_USERNAME': '',
'MYSQL_DATABASE_PASSWORD': ''},
'oura': {'OURA_API_KEY': ''},
'discord': {'DISCORD_API_KEY': '', 'DISCORD_COMMAND_PREFIX': '/AGiXT'},
'github': {'GITHUB_USERNAME': '', 'GITHUB_API_KEY': ''},
'AGiXT Chains': {'Think twice': {'user_input': ''}}]}
"""

""" get_extensions output:
{"extensions":
[{'extension_name': 'Long Term Memory',
'description': "The Long Term Memory extension enables AGiXT to create and manage persistent memory databases.\nIt provides commands for:\n- Creating specialized memory databases for different types of information\n- Organizing and storing memories in structured tables\n- Retrieving specific memories through SQL queries\n- Tracking metadata about stored knowledge\n- Managing the evolution of memory organization over time\n\nThis extension allows agents to maintain their own organized, searchable knowledge bases\nthat persist across conversations. This acts as the assistant's very long-term memory.",
'settings': [],
'commands': [{'friendly_name': 'Create Memory Database',
'description': 'Create a new memory database for storing and organizing information. This command should be used whenever the agent wants to:\n- Create a new category of memories or knowledge\n- Start tracking a new type of information\n- Organize related data in a structured way\n\nExamples of when to use this command:\n- Creating a database for learning progress in a specific subject\n- Starting a database for tracking project-related information\n- Creating a database for storing research findings\n- Making a database for conversation summaries\n- Creating specialized databases for different types of technical knowledge\n\nArgs:\nname (str): Name of the database (e.g., "russian_learning", "project_memories", "technical_docs")\ndescription (str): Detailed description of what this database stores and its purpose\n\nReturns:\nstr: Success message confirming database creation\n\nExample Usage:\n<execute>\n<name>Create Memory Database</name>\n<name>russian_vocabulary</name>\n<description>Database for storing Russian vocabulary words, phrases, and usage examples learned during conversations, including difficulty levels and practice timestamps.</description>\n</execute>',
'command_name': 'create_memory_database',
'command_args': {'name': '', 'description': ''}},
{'friendly_name': 'Remember This',
'description': "Store new information in the assistant's long-term memory. This command should be used when:\n- Learning new information that should be remembered later\n- Saving important facts, concepts, or insights\n- Recording structured information for future reference\n- Creating persistent knowledge that should be available across conversations\n- Building up knowledge bases for specific topics\n\nThe assistant will:\n- Analyze what type of information is being stored\n- Choose or create an appropriate memory database\n- Design or use existing table structures\n- Store the information with relevant metadata\n- Verify successful storage\n\nArgs:\ncontent (str): The information to remember (e.g., facts, concepts, structured data)\nmemory_type (str, optional): Category or type of memory to help with organization\n\nExample Usage:\n<execute>\n<name>Store in Long Term Memory</name>\n<content>The word 'полка' means 'shelf' in Russian. Common usage is 'Книга на полке' meaning 'The book is on the shelf'. This is a frequently used noun in household contexts.</content>\n<memory_type>russian_vocabulary</memory_type>\n</execute>\n\nReturns:\nstr: Confirmation of what was stored and where it can be found",
'command_name': 'store_memory',
'command_args': {'content': '', 'memory_type': ''}},
{'friendly_name': 'List Memory Databases',
'description': 'List all available memory databases and their descriptions. This command should be used when:\n- Deciding which database to store new information in\n- Looking for existing knowledge on a topic\n- Planning where to organize new information\n- Reviewing available knowledge categories\n- Checking when databases were last updated\n\nThe command returns a CSV formatted list containing:\n- Database names\n- Their descriptions\n- Creation dates\n- Last modification dates\n\nThis is particularly useful for:\n- Finding the right database for storing new information\n- Discovering existing knowledge bases\n- Maintaining organization of memories\n- Tracking knowledge evolution over time\n\nReturns:\nstr: CSV formatted list of all memory databases with their metadata\n\nExample Output:\n```csv\n"Database Name","Description","Created Date","Last Modified"\n"russian_vocabulary","Storage for Russian language learning progress","2024-01-01 12:00:00","2024-01-02 15:30:00"\n"project_notes","Technical documentation and decision history for current project","2024-01-01 09:00:00","2024-01-02 14:45:00"\n```',
'command_name': 'list_memory_databases',
'command_args': {}}]
}
"""

""" get_commands output:
{"commands":
{'Create Memory Database': False,
'Remember This': False,
'List Memory Databases': False,
'Update Memory Database Description': False,
'Retrieve Memories': False,
'Send Email with Sendgrid': False,
}
}
"""


# Input types
Expand Down
28 changes: 18 additions & 10 deletions agixt/graphqlendpoints/Memories.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
from typing import List, Dict, Any, Optional
import strawberry
from fastapi import Depends, HTTPException, Header
from fastapi import HTTPException
from Models import (
AgentMemoryQuery,
TextMemoryInput,
FileInput,
UrlInput,
ResponseMessage,
Dataset,
FinetuneAgentModel,
ExternalSource,
UserInput,
FeedbackInput,
MemoryResponse,
MemoryCollectionResponse,
DPOResponse,
)
from endpoints.Memory import (
query_memories as rest_query_memories,
Expand All @@ -35,23 +31,35 @@
from ApiClient import verify_api_key


@strawberry.type
class Memory:
external_source_name: str
id: str
description: str
text: str
embedding: str
additional_metadata: str
key: str
timestamp: str


# Convert Pydantic models to Strawberry types
@strawberry.experimental.pydantic.type(model=MemoryResponse)
@strawberry.type
class MemoryResponseType:
memories: List[Dict[str, Any]]
memories: List[Memory]


@strawberry.experimental.pydantic.type(model=MemoryCollectionResponse)
@strawberry.type
class MemoryCollectionResponseType:
external_sources: List[str]


@strawberry.experimental.pydantic.type(model=ResponseMessage)
@strawberry.type
class ResponseMessageType:
message: str


@strawberry.experimental.pydantic.type(model=DPOResponse)
@strawberry.type
class DPOResponseType:
prompt: str
chosen: str
Expand Down
13 changes: 7 additions & 6 deletions agixt/graphqlendpoints/Schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
# from graphqlendpoints.Auth import schema as auth_schema
# from graphqlendpoints.Chains import schema as chains_schema
# from graphqlendpoints.Completions import schema as completions_schema
# from graphqlendpoints.Memories import schema as memories_schema
# from graphqlendpoints.Extensions import schema as extensions_schema

from graphqlendpoints.Memories import schema as memories_schema
from graphqlendpoints.Conversations import schema as conversations_schema
from graphqlendpoints.Extensions import schema as extensions_schema
from graphqlendpoints.Prompts import schema as prompts_schema
from graphqlendpoints.Providers import schema as providers_schema

Expand All @@ -17,9 +18,9 @@ class Query(
# auth_schema.Query,
# chains_schema.Query,
# completions_schema.Query,
# memories_schema.Query,
memories_schema.Query,
conversations_schema.Query,
extensions_schema.Query,
# extensions_schema.Query,
prompts_schema.Query,
providers_schema.Query,
):
Expand All @@ -32,9 +33,9 @@ class Mutation(
# auth_schema.Mutation,
# chains_schema.Mutation,
# completions_schema.Mutation,
# memories_schema.Mutation,
memories_schema.Mutation,
conversations_schema.Mutation,
extensions_schema.Mutation,
# extensions_schema.Mutation,
prompts_schema.Mutation,
providers_schema.Mutation,
):
Expand Down

0 comments on commit db14134

Please sign in to comment.