simile 0.4.3__tar.gz → 0.4.5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: simile
3
- Version: 0.4.3
3
+ Version: 0.4.5
4
4
  Summary: Package for interfacing with Simile AI agents for simulation
5
5
  Author-email: Simile AI <cqz@simile.ai>
6
6
  License: MIT
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "simile"
7
- version = "0.4.3"
7
+ version = "0.4.5"
8
8
  authors = [
9
9
  { name="Simile AI", email="cqz@simile.ai" },
10
10
  ]
@@ -7,6 +7,7 @@ from pydantic import BaseModel
7
7
  from .models import (
8
8
  Population,
9
9
  PopulationInfo,
10
+ UpdatePopulationMetadataPayload,
10
11
  Agent as AgentModel,
11
12
  DataItem,
12
13
  DeletionResponse,
@@ -164,6 +165,32 @@ class Simile:
164
165
  )
165
166
  return response_data
166
167
 
168
+ async def update_population_metadata(
169
+ self,
170
+ population_id: Union[str, uuid.UUID],
171
+ metadata: Dict[str, Any],
172
+ mode: str = "merge",
173
+ ) -> Population:
174
+ """
175
+ Update a population's metadata (jsonb).
176
+
177
+ Args:
178
+ population_id: The ID of the population
179
+ metadata: A dictionary of metadata to merge or replace
180
+ mode: Either "merge" (default) or "replace"
181
+
182
+ Returns:
183
+ Updated Population object
184
+ """
185
+ payload = UpdatePopulationMetadataPayload(metadata=metadata, mode=mode)
186
+ response_data = await self._request(
187
+ "PATCH",
188
+ f"populations/{str(population_id)}/metadata",
189
+ json=payload,
190
+ response_model=Population,
191
+ )
192
+ return response_data
193
+
167
194
  async def get_population(self, population_id: Union[str, uuid.UUID]) -> Population:
168
195
  response_data = await self._request(
169
196
  "GET", f"populations/get/{str(population_id)}", response_model=Population
@@ -203,6 +230,8 @@ class Simile:
203
230
  async def create_agent(
204
231
  self,
205
232
  name: str,
233
+ source: Optional[str] = None,
234
+ source_id: Optional[str] = None,
206
235
  population_id: Optional[Union[str, uuid.UUID]] = None,
207
236
  agent_data: Optional[List[Dict[str, Any]]] = None,
208
237
  ) -> AgentModel:
@@ -255,16 +284,16 @@ class Simile:
255
284
  "DELETE", f"agents/{str(agent_id)}/populations/{str(population_id)}"
256
285
  )
257
286
  return raw_response.json()
258
-
287
+
259
288
  async def batch_add_agents_to_population(
260
- self, agent_ids: List[Union[str, uuid.UUID]], population_id: Union[str, uuid.UUID]
289
+ self,
290
+ agent_ids: List[Union[str, uuid.UUID]],
291
+ population_id: Union[str, uuid.UUID],
261
292
  ) -> Dict[str, Any]:
262
293
  """Add multiple agents to a population in a single batch operation."""
263
294
  agent_id_strs = [str(aid) for aid in agent_ids]
264
295
  raw_response = await self._request(
265
- "POST",
266
- f"populations/{str(population_id)}/agents/batch",
267
- json=agent_id_strs
296
+ "POST", f"populations/{str(population_id)}/agents/batch", json=agent_id_strs
268
297
  )
269
298
  return raw_response.json()
270
299
 
@@ -419,12 +448,16 @@ class Simile:
419
448
  evidence: bool = False,
420
449
  confidence: bool = False,
421
450
  memory_stream: Optional[MemoryStream] = None,
422
- use_memory: Optional[Union[str, uuid.UUID]] = None, # Session ID to load memory from
451
+ use_memory: Optional[
452
+ Union[str, uuid.UUID]
453
+ ] = None, # Session ID to load memory from
423
454
  exclude_memory_ids: Optional[List[str]] = None, # Study/question IDs to exclude
424
- save_memory: Optional[Union[str, uuid.UUID]] = None, # Session ID to save memory to
455
+ save_memory: Optional[
456
+ Union[str, uuid.UUID]
457
+ ] = None, # Session ID to save memory to
425
458
  ) -> OpenGenerationResponse:
426
459
  """Generates an open response from an agent based on a question.
427
-
460
+
428
461
  Args:
429
462
  agent_id: The agent to query
430
463
  question: The question to ask
@@ -448,30 +481,30 @@ class Simile:
448
481
  "evidence": evidence,
449
482
  "confidence": confidence,
450
483
  }
451
-
484
+
452
485
  # Pass memory parameters to API for server-side handling
453
486
  if use_memory:
454
487
  request_payload["use_memory"] = str(use_memory)
455
488
  if exclude_memory_ids:
456
489
  request_payload["exclude_memory_ids"] = exclude_memory_ids
457
-
490
+
458
491
  if save_memory:
459
492
  request_payload["save_memory"] = str(save_memory)
460
-
493
+
461
494
  # Only include explicit memory_stream if provided directly
462
495
  if memory_stream:
463
496
  request_payload["memory_stream"] = memory_stream.to_dict()
464
-
497
+
465
498
  response_data = await self._request(
466
499
  "POST",
467
500
  endpoint,
468
501
  json=request_payload,
469
502
  response_model=OpenGenerationResponse,
470
503
  )
471
-
504
+
472
505
  # Don't save memory here - API should handle it when save_memory is passed
473
506
  # Memory saving is now handled server-side for better performance
474
-
507
+
475
508
  return response_data
476
509
 
477
510
  async def generate_closed_response(
@@ -486,12 +519,16 @@ class Simile:
486
519
  evidence: bool = False,
487
520
  confidence: bool = False,
488
521
  memory_stream: Optional[MemoryStream] = None,
489
- use_memory: Optional[Union[str, uuid.UUID]] = None, # Session ID to load memory from
522
+ use_memory: Optional[
523
+ Union[str, uuid.UUID]
524
+ ] = None, # Session ID to load memory from
490
525
  exclude_memory_ids: Optional[List[str]] = None, # Study/question IDs to exclude
491
- save_memory: Optional[Union[str, uuid.UUID]] = None, # Session ID to save memory to
526
+ save_memory: Optional[
527
+ Union[str, uuid.UUID]
528
+ ] = None, # Session ID to save memory to
492
529
  ) -> ClosedGenerationResponse:
493
530
  """Generates a closed response from an agent.
494
-
531
+
495
532
  Args:
496
533
  agent_id: The agent to query
497
534
  question: The question to ask
@@ -517,34 +554,34 @@ class Simile:
517
554
  "evidence": evidence,
518
555
  "confidence": confidence,
519
556
  }
520
-
557
+
521
558
  # Pass memory parameters to API for server-side handling
522
559
  if use_memory:
523
560
  request_payload["use_memory"] = str(use_memory)
524
561
  if exclude_memory_ids:
525
562
  request_payload["exclude_memory_ids"] = exclude_memory_ids
526
-
563
+
527
564
  if save_memory:
528
565
  request_payload["save_memory"] = str(save_memory)
529
-
566
+
530
567
  # Only include explicit memory_stream if provided directly
531
568
  if memory_stream:
532
569
  request_payload["memory_stream"] = memory_stream.to_dict()
533
-
570
+
534
571
  response_data = await self._request(
535
572
  "POST",
536
573
  endpoint,
537
574
  json=request_payload,
538
575
  response_model=ClosedGenerationResponse,
539
576
  )
540
-
577
+
541
578
  # Don't save memory here - API should handle it when save_memory is passed
542
579
  # Memory saving is now handled server-side for better performance
543
-
580
+
544
581
  return response_data
545
582
 
546
583
  # Memory Management Methods
547
-
584
+
548
585
  async def save_memory(
549
586
  self,
550
587
  agent_id: Union[str, uuid.UUID],
@@ -559,7 +596,7 @@ class Simile:
559
596
  ) -> str:
560
597
  """
561
598
  Save a response with associated memory information.
562
-
599
+
563
600
  Args:
564
601
  agent_id: The agent ID
565
602
  response: The agent's response text
@@ -570,7 +607,7 @@ class Simile:
570
607
  memory_stream_used: The memory stream that was used
571
608
  reasoning: Optional reasoning
572
609
  metadata: Additional metadata
573
-
610
+
574
611
  Returns:
575
612
  Response ID if saved successfully
576
613
  """
@@ -578,7 +615,7 @@ class Simile:
578
615
  "agent_id": str(agent_id),
579
616
  "response": response,
580
617
  }
581
-
618
+
582
619
  if session_id:
583
620
  payload["session_id"] = str(session_id)
584
621
  if question_id:
@@ -593,13 +630,13 @@ class Simile:
593
630
  payload["reasoning"] = reasoning
594
631
  if metadata:
595
632
  payload["metadata"] = metadata
596
-
633
+
597
634
  response = await self._request("POST", "memory/save", json=payload)
598
635
  data = response.json()
599
636
  if data.get("success"):
600
637
  return data.get("response_id")
601
638
  raise SimileAPIError("Failed to save memory")
602
-
639
+
603
640
  async def get_memory(
604
641
  self,
605
642
  session_id: Union[str, uuid.UUID],
@@ -611,7 +648,7 @@ class Simile:
611
648
  ) -> Optional[MemoryStream]:
612
649
  """
613
650
  Retrieve the memory stream for an agent in a session.
614
-
651
+
615
652
  Args:
616
653
  session_id: Session ID to filter by
617
654
  agent_id: The agent ID
@@ -619,7 +656,7 @@ class Simile:
619
656
  exclude_question_ids: List of question IDs to exclude
620
657
  limit: Maximum number of turns to include
621
658
  use_memory: Whether to use memory at all
622
-
659
+
623
660
  Returns:
624
661
  MemoryStream object or None
625
662
  """
@@ -628,31 +665,31 @@ class Simile:
628
665
  "agent_id": str(agent_id),
629
666
  "use_memory": use_memory,
630
667
  }
631
-
668
+
632
669
  if exclude_study_ids:
633
670
  payload["exclude_study_ids"] = [str(id) for id in exclude_study_ids]
634
671
  if exclude_question_ids:
635
672
  payload["exclude_question_ids"] = [str(id) for id in exclude_question_ids]
636
673
  if limit:
637
674
  payload["limit"] = limit
638
-
675
+
639
676
  response = await self._request("POST", "memory/get", json=payload)
640
677
  data = response.json()
641
-
678
+
642
679
  if data.get("success") and data.get("memory_stream"):
643
680
  return MemoryStream.from_dict(data["memory_stream"])
644
681
  return None
645
-
682
+
646
683
  async def get_memory_summary(
647
684
  self,
648
685
  session_id: Union[str, uuid.UUID],
649
686
  ) -> Dict[str, Any]:
650
687
  """
651
688
  Get a summary of memory usage for a session.
652
-
689
+
653
690
  Args:
654
691
  session_id: Session ID to analyze
655
-
692
+
656
693
  Returns:
657
694
  Dictionary with memory statistics
658
695
  """
@@ -661,7 +698,7 @@ class Simile:
661
698
  if data.get("success"):
662
699
  return data.get("summary", {})
663
700
  return {}
664
-
701
+
665
702
  async def clear_memory(
666
703
  self,
667
704
  session_id: Union[str, uuid.UUID],
@@ -670,28 +707,28 @@ class Simile:
670
707
  ) -> bool:
671
708
  """
672
709
  Clear memory for a session, optionally filtered by agent or study.
673
-
710
+
674
711
  Args:
675
712
  session_id: Session ID to clear memory for
676
713
  agent_id: Optional agent ID to filter by
677
714
  study_id: Optional study ID to filter by
678
-
715
+
679
716
  Returns:
680
717
  True if cleared successfully, False otherwise
681
718
  """
682
719
  payload = {
683
720
  "session_id": str(session_id),
684
721
  }
685
-
722
+
686
723
  if agent_id:
687
724
  payload["agent_id"] = str(agent_id)
688
725
  if study_id:
689
726
  payload["study_id"] = str(study_id)
690
-
727
+
691
728
  response = await self._request("POST", "memory/clear", json=payload)
692
729
  data = response.json()
693
730
  return data.get("success", False)
694
-
731
+
695
732
  async def copy_memory(
696
733
  self,
697
734
  from_session_id: Union[str, uuid.UUID],
@@ -700,12 +737,12 @@ class Simile:
700
737
  ) -> int:
701
738
  """
702
739
  Copy memory from one session to another.
703
-
740
+
704
741
  Args:
705
742
  from_session_id: Source session ID
706
743
  to_session_id: Destination session ID
707
744
  agent_id: Optional agent ID to filter by
708
-
745
+
709
746
  Returns:
710
747
  Number of memory turns copied
711
748
  """
@@ -713,10 +750,10 @@ class Simile:
713
750
  "from_session_id": str(from_session_id),
714
751
  "to_session_id": str(to_session_id),
715
752
  }
716
-
753
+
717
754
  if agent_id:
718
755
  payload["agent_id"] = str(agent_id)
719
-
756
+
720
757
  response = await self._request("POST", "memory/copy", json=payload)
721
758
  data = response.json()
722
759
  if data.get("success"):
@@ -11,6 +11,7 @@ class Population(BaseModel):
11
11
  description: Optional[str] = None
12
12
  created_at: datetime
13
13
  updated_at: datetime
14
+ metadata: Optional[Dict[str, Any]] = None
14
15
 
15
16
 
16
17
  class PopulationInfo(BaseModel):
@@ -18,6 +19,7 @@ class PopulationInfo(BaseModel):
18
19
  name: str
19
20
  description: Optional[str] = None
20
21
  agent_count: int
22
+ metadata: Optional[Dict[str, Any]] = None
21
23
 
22
24
 
23
25
  class DataItem(BaseModel):
@@ -37,6 +39,8 @@ class Agent(BaseModel):
37
39
  created_at: datetime
38
40
  updated_at: datetime
39
41
  data_items: List[DataItem] = Field(default_factory=list)
42
+ source: Optional[str] = None
43
+ source_id: Optional[str] = None
40
44
 
41
45
 
42
46
  class CreatePopulationPayload(BaseModel):
@@ -44,6 +48,11 @@ class CreatePopulationPayload(BaseModel):
44
48
  description: Optional[str] = None
45
49
 
46
50
 
51
+ class UpdatePopulationMetadataPayload(BaseModel):
52
+ metadata: Dict[str, Any]
53
+ mode: Optional[Literal["merge", "replace"]] = "merge"
54
+
55
+
47
56
  class InitialDataItemPayload(BaseModel):
48
57
  data_type: str
49
58
  content: Any
@@ -52,6 +61,8 @@ class InitialDataItemPayload(BaseModel):
52
61
 
53
62
  class CreateAgentPayload(BaseModel):
54
63
  name: str
64
+ source: Optional[str] = None
65
+ source_id: Optional[str] = None
55
66
  population_id: Optional[uuid.UUID] = None
56
67
  agent_data: Optional[List[InitialDataItemPayload]] = None
57
68
 
@@ -259,7 +270,7 @@ class BaseMemoryTurn(BaseModel):
259
270
 
260
271
  class Config:
261
272
  use_enum_values = True
262
-
273
+
263
274
  def to_dict(self) -> Dict[str, Any]:
264
275
  """Convert to dictionary for serialization."""
265
276
  data = self.model_dump()
@@ -354,9 +365,7 @@ class MemoryStream(BaseModel):
354
365
 
355
366
  def to_dict(self) -> Dict[str, Any]:
356
367
  """Convert memory stream to a dictionary for serialization."""
357
- return {
358
- "turns": [turn.to_dict() for turn in self.turns]
359
- }
368
+ return {"turns": [turn.to_dict() for turn in self.turns]}
360
369
 
361
370
  @classmethod
362
371
  def from_dict(cls, data: Dict[str, Any]) -> "MemoryStream":
@@ -377,7 +386,9 @@ class MemoryStream(BaseModel):
377
386
  def fork(self, up_to_index: Optional[int] = None) -> "MemoryStream":
378
387
  """Create a copy of this memory stream, optionally up to a specific index."""
379
388
  new_memory = MemoryStream()
380
- turns_to_copy = self.turns[:up_to_index] if up_to_index is not None else self.turns
389
+ turns_to_copy = (
390
+ self.turns[:up_to_index] if up_to_index is not None else self.turns
391
+ )
381
392
  for turn in turns_to_copy:
382
393
  new_memory.add_turn(turn.model_copy())
383
394
  return new_memory
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: simile
3
- Version: 0.4.3
3
+ Version: 0.4.5
4
4
  Summary: Package for interfacing with Simile AI agents for simulation
5
5
  Author-email: Simile AI <cqz@simile.ai>
6
6
  License: MIT
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes