|
| 1 | +/** |
| 2 | + * Provides classes modeling security-relevant aspects of the `openAI` Agents SDK package. |
| 3 | + * See https://github.com/openai/openai-agents-python. |
| 4 | + * As well as the regular openai python interface. |
| 5 | + * See https://github.com/openai/openai-python. |
| 6 | + */ |
| 7 | + |
| 8 | +private import python |
| 9 | +private import semmle.python.ApiGraphs |
| 10 | + |
| 11 | +/** |
| 12 | + * Provides models for agents SDK (instances of the `agents.Runner` class etc). |
| 13 | + * |
| 14 | + * See https://github.com/openai/openai-agents-python. |
| 15 | + */ |
| 16 | +module AgentSDK { |
| 17 | + /** Gets a reference to the `agents.Runner` class. */ |
| 18 | + API::Node classRef() { result = API::moduleImport("agents").getMember("Runner") } |
| 19 | + |
| 20 | + /** Gets a reference to the `run` members. */ |
| 21 | + API::Node runMembers() { result = classRef().getMember(["run", "run_sync", "run_streamed"]) } |
| 22 | + |
| 23 | + /** Gets a reference to a potential property of `agents.Runner` called input which can refer to a system prompt depending on the role specified. */ |
| 24 | + API::Node getContentNode() { |
| 25 | + result = runMembers().getKeywordParameter("input").getASubscript().getSubscript("content") |
| 26 | + or |
| 27 | + result = runMembers().getParameter(_).getASubscript().getSubscript("content") |
| 28 | + } |
| 29 | +} |
| 30 | + |
| 31 | +/** |
| 32 | + * Provides models for Agent (instances of the `openai.OpenAI` class). |
| 33 | + * |
| 34 | + * See https://github.com/openai/openai-python. |
| 35 | + */ |
| 36 | +module OpenAI { |
| 37 | + /** Gets a reference to the `openai.OpenAI` class. */ |
| 38 | + API::Node classRef() { |
| 39 | + result = |
| 40 | + API::moduleImport("openai").getMember(["OpenAI", "AsyncOpenAI", "AzureOpenAI"]).getReturn() |
| 41 | + } |
| 42 | + |
| 43 | + /** Gets a reference to a potential property of `openai.OpenAI` called instructions which refers to the system prompt. */ |
| 44 | + API::Node getContentNode() { |
| 45 | + exists(API::Node content | |
| 46 | + content = |
| 47 | + classRef() |
| 48 | + .getMember("responses") |
| 49 | + .getMember("create") |
| 50 | + .getKeywordParameter(["input", "instructions"]) |
| 51 | + or |
| 52 | + content = |
| 53 | + classRef() |
| 54 | + .getMember("responses") |
| 55 | + .getMember("create") |
| 56 | + .getKeywordParameter(["input", "instructions"]) |
| 57 | + .getASubscript() |
| 58 | + .getSubscript("content") |
| 59 | + or |
| 60 | + content = |
| 61 | + classRef() |
| 62 | + .getMember("realtime") |
| 63 | + .getMember("connect") |
| 64 | + .getReturn() |
| 65 | + .getMember("conversation") |
| 66 | + .getMember("item") |
| 67 | + .getMember("create") |
| 68 | + .getKeywordParameter("item") |
| 69 | + .getSubscript("content") |
| 70 | + or |
| 71 | + content = |
| 72 | + classRef() |
| 73 | + .getMember("chat") |
| 74 | + .getMember("completions") |
| 75 | + .getMember("create") |
| 76 | + .getKeywordParameter("messages") |
| 77 | + .getASubscript() |
| 78 | + .getSubscript("content") |
| 79 | + | |
| 80 | + // content |
| 81 | + if not exists(content.getASubscript()) |
| 82 | + then result = content |
| 83 | + else |
| 84 | + // content.text |
| 85 | + result = content.getASubscript().getSubscript("text") |
| 86 | + ) |
| 87 | + } |
| 88 | +} |
0 commit comments