I have a baseAgent that copies over old chat_ctx a...
# ask-ai
r
I have a baseAgent that copies over old chat_ctx and removes the instructions. However there's one set of instructions I'd like to keep for all the agents. How do I do that
t
Thanks for reaching out, Weilan. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Could you clarify how your baseAgent is currently configured to copy the old chat context and remove instructions? Additionally, could you specify the format or criteria for the instructions you'd like to keep? This will help in providing a more tailored solution.
r
The instructions give context to the the agent. I am using multiagents that each handle a partt of a question
Copy code
class BaseAgent(Agent):
    def __init__(self, agent_config: Optional[dict] = None, **kwargs):
        super().__init__(**kwargs)
        self.agent_config = agent_config or {}

    async def on_enter(self) -> None:
        agent_name = self.__class__.__name__
        <http://logger.info|logger.info>(f"entering task {agent_name}")

        userdata: UserData = self.session.userdata
        chat_ctx = self.chat_ctx.copy()
        print(f"Chat context for {agent_name}: {chat_ctx.items}")
        # add the previous agent's chat history to the current agent
        if isinstance(userdata.prev_agent, Agent):
            truncated_chat_ctx = userdata.prev_agent.chat_ctx.copy(
                exclude_instructions=True, exclude_function_call=False
            )
            print(f"Truncated chat context: {truncated_chat_ctx.items}")
            existing_ids = {item.id for item in chat_ctx.items}
            items_copy = [
                item for item in truncated_chat_ctx.items if item.id not in existing_ids
            ]
            chat_ctx.items.extend(items_copy)

        await self.update_chat_ctx(chat_ctx)
        await self.enter()
t
Hey there! 👋 I totally get what you're asking about. Could you help me understand a bit more about how those instructions are laid out? If you could share some details about their format—like if they use special tags, keywords, or anything that makes them stand out—I'd be super happy to brainstorm the best way to keep the important ones while clearing out the rest. I'm all ears and want to make sure we nail exactly what you need! 😊
r
I'm using voice agent. And I'm gathering intel for a lead. I want to pass in context for how I want the ai to behave which will be the same for any of the agents. Each agent has specific instructions: ex:
Copy code
class GreeterAgent(BaseAgent):
    def __init__(self, agent_config: dict) -> None:

        instructions = agent_config.get(
            "instructions", DEFAULT_GREETER_AGENT_INSTRUCTIONS
        )
        super().__init__(
            instructions=instructions,
        )
but I also want them to have the general instructions too and that is applicable to all agents
t
Hey there! 👋 I totally get your question about instruction handling. Let me break this down in a friendly way. Are you looking to have the general instructions either added to each agent's specific instructions or used to fill in any gaps? And I'm curious - do you have a central spot where these general instructions are stored that all agents can easily tap into? Happy to help you figure out the best approach! 😊
r
yes. I do. Do I have to give this information to each agent or can I just give it once?
t
I don't have the answer you're looking for. You could also try asking your question: • in one of the other Slack channels or • to https://deepwiki.com/livekit/livekit_composite which is trained on all LiveKit source code If you find the answer, please post it here to help others!