Inherited API-keys #230
|
Hello everybody, Here a code example: The key is valid and it even generates an answer: The prompt_driver variable is already redundant as ToolkitTask should get the key from the pipeline (if no other is specified). Otherwise you would have to set the api key for each and every Task and tool it uses. Is there something that I overlook? Regards |
Replies: 3 comments 3 replies
|
Hey @urlmonitor! I just ran a slightly modified version of your example on griptape import os
from griptape.structures import Pipeline
from griptape.drivers import OpenAiChatPromptDriver
from griptape.tasks import ToolkitTask
from griptape.tools import WebScraper
openai_api_key = os.environ["OPENAI_API_KEY"]
llm_version = 'gpt-4'
pipeline = Pipeline(
prompt_driver=OpenAiChatPromptDriver(
temperature=0,
model=llm_version,
api_key=openai_api_key,
)
)
prompt_driver = OpenAiChatPromptDriver(
api_key=openai_api_key,
)
pipeline.add_tasks(
ToolkitTask(
"{{ args[0] }}. In case you want to use WebScraper, load the URL, and answer the users question.",
tools=[
WebScraper(),
],
prompt_driver=prompt_driver,
)
)
pipeline.run("Based on the website https://griptape.ai, tell me what griptape is.") |
|
It works for you as you have this os.environ["OPENAI_API_KEY"]. Try setting the key as a string and remove it from env. It works for me as well, when I dynamically set os.environ, but in a prod environment with multiple users this is probably not the best idea :D |
|
Inherited API keys for nested tasks is a critical design decision that affects both security and cost attribution in agent pipelines. The pattern we use in KinthAI for agent-to-agent key inheritance: monotonic capability narrowing. When a parent agent spawns a child, the child can only receive a strict subset of the parent's capabilities and a fraction of the parent's budget. The child cannot escalate its own permissions or access APIs the parent didn't explicitly delegate. Implementation detail that matters: the narrowing needs to happen at token issuance time, not at runtime check. If you check "does child have permission to use this API key" when the API call happens, there's a window where the child can accumulate resources before the check fires. Pre-narrowing at delegation time closes that window. For API key specifically:
The tricky case is when you don't know in advance what APIs the child will need. We handle this with capability negotiation before spawning: the child declares what it needs, the parent approves or denies each capability explicitly. More on the delegation chain design: https://blog.kinthai.ai/221-agents-multi-agent-coordination-lessons Is the inheritance use case primarily for multi-user access control, or for agent-spawns-sub-agent scenarios? |
@urlmonitor As of v0.17.0, you can now more easily specify an embedding driver that uses your API key: