Skip to content

Commit f249e82

Browse files
authored
Merge pull request #19 from picahq/feat/action-permission-control
feat: add action control and access permission
2 parents 1123970 + c4672c7 commit f249e82

15 files changed

+200
-39
lines changed

README.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ The `PicaClientOptions` class allows you to configure the Pica client with the f
2222
| --- | --- | --- | --- | --- |
2323
| server_url | str | No | https://api.picaos.com | URL for self-hosted Pica server. |
2424
| connectors | List[str] | No | [] | List of connector keys to filter by. Pass ["*"] to initialize all available connectors, or specific connector keys to filter. If empty, no connections will be initialized. |
25+
| actions | List[str] | No | None | List of action ids to filter by. Default is all actions. |
26+
| permissions | Literal["read", "write", "admin"] | No | None | Permission level to filter actions by. 'read' allows GET only, 'write' allows POST/PUT/PATCH, 'admin' allows all methods (default: 'admin') |
2527
| authkit | bool | No | False | If True, the SDK will use Authkit to connect to prompt the user to connect to a platform that they do not currently have access to |
2628
| identity | str | No | None | Filter connections by specific identity ID. |
2729
| identity_type | "user", "team", "organization", or "project" | No | None | Filter connections by identity type. |
@@ -52,15 +54,19 @@ pica_client = PicaClient(
5254
# identity_type="user"
5355
# identity="user-id",
5456
# authkit=True,
55-
57+
# actions=[""], # Initialize specific action ids (e.g. ["conn_mod_def::F_JeJ_A_TKg::cc2kvVQQTiiIiLEDauy6zQ"])
58+
# permissions="read", # Filter actions by permission level
59+
5660
connectors=["*"] # Initialize all available connections for this example
5761
)
5862
)
5963

64+
pica_client.initialize()
65+
6066
# Create a LangChain agent with Pica tools
6167
llm = ChatOpenAI(
6268
temperature=0,
63-
model="gpt-4o"
69+
model="gpt-4.1"
6470
)
6571

6672
# Create an agent with Pica tools
@@ -95,11 +101,13 @@ from pica_langchain import PicaClient, create_pica_tools
95101
# Initialize the Pica client
96102
pica_client = PicaClient(secret="your-pica-secret")
97103

104+
pica_client.initialize()
105+
98106
# Create Pica tools
99107
tools = create_pica_tools(pica_client)
100108

101109
# Create a custom agent with the tools
102-
llm = ChatOpenAI(temperature=0, model="gpt-4o")
110+
llm = ChatOpenAI(temperature=0, model="gpt-4.1")
103111
agent = initialize_agent(
104112
tools,
105113
llm,
@@ -145,7 +153,7 @@ async def main():
145153
)
146154

147155
# Create an agent with both Pica and MCP tools
148-
llm = ChatOpenAI(temperature=0, model="gpt-4o")
156+
llm = ChatOpenAI(temperature=0, model="gpt-4.1")
149157
agent = create_pica_agent(
150158
client=pica_client,
151159
llm=llm,
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
"""
2+
Example demonstrating how to use pica-langchain with LangChain streaming responses.
3+
"""
4+
5+
import os
6+
import sys
7+
8+
from langchain_openai import ChatOpenAI
9+
from langchain.agents import AgentType
10+
from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler
11+
from pica_langchain import PicaClient, create_pica_agent
12+
from pica_langchain.models import PicaClientOptions
13+
14+
15+
def get_env_var(name: str) -> str:
16+
"""Get environment variable or exit if not set."""
17+
value = os.environ.get(name)
18+
19+
if not value:
20+
print(f"ERROR: {name} environment variable must be set")
21+
sys.exit(1)
22+
23+
return value
24+
25+
26+
def main():
27+
try:
28+
# Create an agent with access to only the Send Email action from Gmail
29+
pica_client = PicaClient(
30+
secret=get_env_var("PICA_SECRET"),
31+
options=PicaClientOptions(
32+
connectors=["my-gmail-connector-key"],
33+
actions=[
34+
"conn_mod_def::F_JeJ_A_TKg::cc2kvVQQTiiIiLEDauy6zQ"
35+
]
36+
)
37+
)
38+
39+
pica_client.initialize()
40+
41+
llm_with_handler = ChatOpenAI(
42+
temperature=0,
43+
model="gpt-4.1",
44+
streaming=True,
45+
callbacks=[StreamingStdOutCallbackHandler()]
46+
)
47+
48+
agent_with_handler = create_pica_agent(
49+
client=pica_client,
50+
llm=llm_with_handler,
51+
agent_type=AgentType.OPENAI_FUNCTIONS,
52+
)
53+
54+
for chunk in agent_with_handler.stream({
55+
"input": "What actions do I have access to with Gmail?"
56+
}):
57+
if 'output' in chunk:
58+
print(chunk['output'])
59+
60+
except Exception as e:
61+
print(f"ERROR: An unexpected error occurred: {e}")
62+
sys.exit(1)
63+
64+
65+
if __name__ == "__main__":
66+
main()

examples/async_with_pica.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ async def main():
4343
# Create an LLM with streaming capability
4444
llm = ChatOpenAI(
4545
temperature=0,
46-
model="gpt-4o",
46+
model="gpt-4.1",
4747
streaming=True,
4848
callbacks=[StreamingStdOutCallbackHandler()]
4949
)

examples/authkit_example.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def main():
3434

3535
llm = ChatOpenAI(
3636
temperature=0,
37-
model="gpt-4o",
37+
model="gpt-4.1",
3838
)
3939

4040
# Create an agent with Pica tools

examples/confirm_before_executing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def main():
9393

9494
llm = ChatOpenAI(
9595
temperature=0,
96-
model="gpt-4o",
96+
model="gpt-4.1",
9797
)
9898

9999
agent = create_pica_agent(

examples/confirm_before_executing_streaming.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ async def main():
142142

143143
llm = ChatOpenAI(
144144
temperature=0,
145-
model="gpt-4o",
145+
model="gpt-4.1",
146146
streaming=True,
147147
callbacks=[StreamingStdOutCallbackHandler()]
148148
)

examples/streaming_example.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def main():
3434

3535
llm_with_handler = ChatOpenAI(
3636
temperature=0,
37-
model="gpt-4o",
37+
model="gpt-4.1",
3838
streaming=True,
3939
callbacks=[StreamingStdOutCallbackHandler()]
4040
)

examples/streaming_with_intermediate_steps.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def main():
3434

3535
llm_with_handler = ChatOpenAI(
3636
temperature=0,
37-
model="gpt-4o",
37+
model="gpt-4.1",
3838
streaming=True,
3939
callbacks=[StreamingStdOutCallbackHandler()]
4040
)

examples/use_with_langchain.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def main():
3737

3838
llm = ChatOpenAI(
3939
temperature=0,
40-
model="gpt-4o",
40+
model="gpt-4.1",
4141
)
4242

4343
# Create an agent with Pica tools

examples/use_with_langchain_github.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def main():
3232

3333
llm = ChatOpenAI(
3434
temperature=0,
35-
model="gpt-4o",
35+
model="gpt-4.1",
3636
)
3737

3838
# Create an agent with Pica tools

0 commit comments

Comments
 (0)