How to pass Some Input to tools from flow state and some by agent?

I have a clientid and client secret for every api call that happens through tools.
I am initializing crews during start of the application and does not want to do that again for each new client id.
Example

class MainFlowState(BaseModel):
    user_msg: str = ""
    routes: list = []
    results_from_routes: list = []
    chat_history: list = []
    complete_chat_history: list = []
    flow_history: list = []
    session_id: str = ""
    client_id: str = ""
    client_secret: str = ""


class MainFlow(Flow[MainFlowState]):
    other_knowledge_base = glob.glob(f"{RAGConfig(file_type="pdf").other_knowledge_base}/*.pdf")
    temp_knowledge_base = glob.glob(f"{RAGConfig(file_type="pdf").temp_knowledge_base}/*.pdf")
    temp2_knowledge_base = glob.glob(f"{RAGConfig(file_type="pdf").temp2_knowledge_base}/*.pdf")

     crews: dict = {
        "ACrew": ACrew().crew(),
        
        "BCrew": BCrew(available_data=temp_knowledge_base).crew(),
        "CCrew": CCrew(available_data=temp2_knowledge_base).crew(),
        "SSCrew": SSCrew().crew(),
        "AICrew": AICrew(available_data=other_knowledge_base).crew(),
        
        "SCrew": SCrew().crew(),
    }
    @start()
    def start_manager(self):
        print("Started Flow")
        
        result = (
            self.crews["ACrew"]
            .kickoff(inputs={
            "user_msg": self.state.user_msg,
            "complete_chat_history": "\n".join([f"{_['role']}: {_['content']}" for _ in self.state.chat_history[:-1]]),
        }))

In this ACrew has tools that needs client_id and client_secret. How do i pass it without giving it to agent?

I solved this by making changes in this crewai library itself.
Now I can pass private arguments during runtime without running the risk of agents printing them by mistake.

Mind sharing the code? I’m having a hard time using the crew in a loop.

Can you elaborate. My issue was i wanted to pass some secrets to tools during runtime.
What does loops have to do with this?

As for code the changes are across multiple files. Try tracing down the invoke funtion in tool_usage from kickoff in crews and add one more argument xyz while tracing in funtions. lastly before invoke, replace the cache funtion in tool with the same funtion but add a wrapper that adds these xyz as arguments.

Make sure to have **kargs in _run in tool funtion definition.
Example

original_func = tool.func

def wrapped_func(*args, **kwargs):
    """
    Wrapper function to inject additional private arguments.
    """
    for k, v in private_arguments.items():
        kwargs[k] = v
    
    return original_func(*args, **kwargs)

# Replace the tool's function with the wrapped one
tool.func = wrapped_func

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.