Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add language model base and work out interactions with planning manager #3850

Conversation

collijk
Copy link
Contributor

@collijk collijk commented May 5, 2023

This PR adds the base abstraction for the language model and adjusts some of the interface of the Planning model to create their communication contract.

@vercel
Copy link

vercel bot commented May 5, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
docs ⬜️ Ignored (Inspect) May 5, 2023 3:32pm

@github-actions github-actions bot added the size/l label May 5, 2023
@p-i- p-i- added the re-arch label May 5, 2023
@collijk
Copy link
Contributor Author

collijk commented May 5, 2023

Some thoughts on how this will work:

# This may happen "client" application side before we create the Agent, I'm thinking

planner = Planner(...)
language_model = LanguageModel(...)

initial_user_input = ... # Application logic for this
objective_prompt = planner.construct_objective_prompt_from_user_input(initial_user_input)
model_response = language_model.determine_agent_objective(objective_prompt)

agent_objective = model_response.content  # This should be parsed into a standard format already

# This may happen on the "server" side (across the message broker interface)
# ...Update API budget, etc. ...



agent = Agent(
    agent_objective, 
    planner,
    language_model, 
    ...,
)
agent.run()
class Agent:

    def __init__(self, agent_objective, planner, language_model, ...):
        self.objective = agent_objective
        self.planner = planner
        self.language_model = language_model
        ...

    def run():
        while True:
            # Logic to construct the context (checking budget, looking for memories, getting user input)
            planning_prompt_context = PlanningPromptContext(...)
            planning_prompt = self.planner.construct_planning_prompt_from_context(planning_prompt_context)
            action_plan_response = self.language_model.plan_next_axtion(planning_prompt)

            action_plan = action_plan_response.content
            
            # ...Update API budget, check for user confirmation, update memory, etc.
            
            # Logic to construct the context ...
            self_feedback_prompt_context = SelfFeedbackPromptContext(...)
            self_feedback_prompt = self.planner.get_self_feedback_prompt(self_feedback_prompt_context)
            self_feedback_response = self.language_model.get_self_feedback(self_feedback_prompt)
            
            self_feedback = self_feedback_response.content

            # ...Update API budget, resolve action plan with self feedback, update memory, do next action, etc.

@Boostrix
Copy link
Contributor

Boostrix commented May 6, 2023

People interested in learning more about ongoing talks about the planning manager, refer to: #3593

@abc.abstractmethod
def __init__(
self,
configuration: Configuration,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wondering, why are we importing the entire configuration here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm starting permissive because we're going to have to port the existing logic into this system and we're going to find edge cases in that port that we can't isolate without significant work. We don't even have the most basic form of encapsulation yet. We can tighten contracts later once we have a little structure to lean on, and our priority in this work is getting that structure in quickly.


@abc.abstractmethod
def get_model_info(self, model_name: str) -> ModelInfo:
"""Get information about a specific model."""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where do we add new models?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good question and one I'll show in concrete implementation. Essentially the core system will define a couple of models. The plugin system may register new ones (eventually). Part of the language model definition will include concrete instances of LanguageModelInfo and EmbeddingModelInfo objects.

Copy link

@Niraj-Kamdar Niraj-Kamdar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some minor questions regarding interface


if typing.TYPE_CHECKING:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we doing this? Is there any recursive import dependencies?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is an import dependency structure, it is currently unclear and in flux and will include cyclic dependencies, I'm proactively making sure the other developers contributing systems don't hit those cyclic dependencies an can work independently. We will resolve imports in the more standard way when all the work is joined.

@abc.abstractmethod
def list_models(self) -> Dict[str, ModelInfo]:
"""List all available models."""
...

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for ellipsis if docstrings. We can get rid of all ellipsis in favor of docstrings to make it more readable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a nitpick and one I don't totally agree with. It also has no bearing on the PR content.

@collijk collijk merged commit 7bcdc5f into Significant-Gravitas:agent-state-encapsulation May 7, 2023
@collijk collijk deleted the language-model-base branch May 7, 2023 00:29
@Pwuts Pwuts mentioned this pull request Sep 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Archived in project
Development

Successfully merging this pull request may close these issues.

5 participants